string.toCharArray()
String.toCharArray() toCharArray to get char array of a string by using all chars as elements.
Returns an array.
Here are some examples with output.
String str = "Welcome to plus2net.com";
System.out.println(str); // display the input string
char my_array[]=str.toCharArray(); // create the array
System.out.println(my_array[5]); // m
We will display all elements of the output array
String str = "plus2net";
char my_array[]=str.toCharArray();
for (int i=0; i<my_array.length;i++) {
System.out.println(my_array[i]);
}
Output
p
l
u
s
2
n
e
t
« All String functions
« Java
This article is written by plus2net.com team.
plus2net.com