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.
filter_none

edit
close

play_arrow

link
brightness_4
code

// 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


Output:

G
e
e
k
s
f
o
r
G
e
e
k
s


My Personal Notes arrow_drop_up

Welcome to Wenzkaba Planet

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.