The java string toCharArray() method converts the given string into a sequence of characters. The returned array length is equal to the length of the string.
Syntax :
public char[] toCharArray() Return : It returns a newly allocated character array.
// Java program to demonstrate // working of toCharArray() method class Gfg { public static void main(String args[]) { String s = "GeeksforGeeks"; char[] gfg = s.toCharArray(); for (int i = 0; i < gfg.length; i++) { System.out.println(gfg[i]); } } } |
Output:
G e e k s f o r G e e k s
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- CharArrayWriter toCharArray() method in Java with examples
- Collator compare(String, String) method in Java with Example
- Collator equals(String, String) method in Java with Example
- Java String isEmpty() method with example
- Java String contains() method with example
- Java String charAt() method with example
- Java String trim() method with Example
- CollationElementIterator setText(String) method in Java with Example
- Java 8 | DoubleToIntFunction Interface in Java with Example
- Arrays.deepToString() in Java with Example
- NavigableMap Interface in Java with Example
- Deque interface in Java with Example
- Swapping items of a list in Java : Collections.swap() with Example
- StringTokenizer class in Java with example | Set 1 ( Constructors)
- Collections.singleton() method in Java with example
- java.util.Currency methods with example
- Beginning Java programming with Hello World Example
- Serialization and Deserialization in Java with Example
- Java Math asin() method with Example
- Map.Entry interface in Java with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

