Tutorials

Java String Methods


String toCharArray() method


In java toCharArray( ) method helps in converting the given String into character array.

 

Example:


public class CharArrayDemo {

         public static void main(String[] args){

                    String str = "Test the code";                               
                    char[] strToChar = str.toCharArray();
                            
                    for(char c : strToChar){
                        System.out.println(c);
                    }

                }

}

OUTPUT:

T
e
s
t
 
t
h
e
 
c
o
d
e
 

 

 



Please Share this page
Views : 98