Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Java String toCharArray() with example

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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
My Personal Notes arrow_drop_up
Last Updated : 04 Dec, 2018
Like Article
Save Article
Similar Reads
Related Tutorials