Java String toCharArray() with example
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]); } } } |
chevron_right
filter_none
Output:
G e e k s f o r G e e k s
Recommended Posts:
- CharArrayWriter toCharArray() method in Java with examples
- Convert a List of String to a comma separated String in Java
- Convert a Set of String to a comma separated String in Java
- Convert an ArrayList of String to a String array in Java
- Convert Set of String to Array of String in Java
- String Literal Vs String Object in Java
- Insert a String into another String in Java
- Java.lang.string.replace() method in Java
- Java.lang.String.matches() in Java
- Java.lang.String.replace() in Java
- Java.lang.String class in Java | Set 2
- Java.lang.String.getByte() in Java
- Java.lang.String.startswith() in Java
- Java.lang.String.copyValueOf() in Java
- Java String indexOf()
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.



