beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

Java – String toCharArray() Method example

By Chaitanya Singh | Filed Under: String handling

The method toCharArray() returns an Array of chars after converting a String into sequence of characters. The returned array length is equal to the length of the String and the sequence of chars in Array matches the sequence of characters in the String.

 public char[] toCharArray()

Example: toCharArray() method

In this example we are converting a String into array of chars using toCharArray() method.

public class CharArrayExample{
   public static void main(String args[]){
       String str = new String("Welcome to BeginnersBook.com");
       char[] array= str.toCharArray();
       System.out.print("Content of Array:");
       for(char c: array){
           System.out.print(c);
       }
   }
}

Output:

Content of Array:Welcome to BeginnersBook.com

Enjoyed this post? Try these related posts

  1. Java String split() Method with examples
  2. Java – String getChars() Method example
  3. Java – String contentEquals() Method example
  4. Java String replace(), replaceFirst() and replaceAll() method
  5. Java String startsWith() Method with example
  6. Java String intern() method explained with examples

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Java Tutorials

  • Learn Java
  • OOPs Concepts
  • Java Collections

Java String

  • Java String

Java String Methods

  • String charAt()
  • String compareTo()
  • String compareToIgnoreCase()
  • String contains()
  • String concat()
  • substring
  • String valueOf()
  • String startsWith()
  • String equals()
  • String format()
  • String endsWith()
  • String indexOf()
  • String lastIndexOf()
  • String length()
  • String replace()
  • String split()
  • String trim()
  • String intern()
  • String isEmpty()
  • String matches()
  • String regionMatches()
  • String contentEquals()
  • String toCharArray()
  • String getBytes()
  • String join()
  • String getChars()
  • String copyValueOf()

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap