Skip to content
Related Articles

Related Articles

Improve Article

Java String toCharArray() with example

  • Difficulty Level : Easy
  • Last Updated : 04 Dec, 2018
Geek Week

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 Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :