Convert string to char array in java

To convert string to char array using String.toCharArray() method of String.


public class ConvertStringToCharArray {
	public static void main(String[] args) {
 
		String str= "visionsdeveloper";
		char[] strCharArray= str.toCharArray();
 
		for(char temp: strCharArray){
			System.out.println(temp);
      		}
	}
}


OutPut :
v
i
s
i
o
n
s
d
e
v
e
l
o
p
e
r

 

If you want to convert String to char array without using built-in function than try below example.


public class ConvertStringToCharArray {
	public static void main(String[] args) {
 
		String str= "visionsdeveloper";
		char[] ch = new char[str.length()];
		for(int i =0;i<str.length();i++){
			ch[i] = str.charAt(i);
		}
		System.out.println(ch[0]);
	}
}