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 : 162
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!