EN
Java - convert string to character array
0 points
In this article, we would like to show you how to convert a string to a character array in Java.
The following example shows how to obtain a character array from a String instance using the toCharArray()
method.
xxxxxxxxxx
1
public class StringExample {
2
3
public static void main(String[] args) {
4
String sampleString = "This is your text...";
5
char[] charArray = sampleString.toCharArray();
6
7
System.out.println( charArray ); // This is your text...
8
9
System.out.println( sampleString.getClass() ); // class java.lang.String
10
System.out.println( charArray.getClass() ); // class [C
11
}
12
}
Output:
xxxxxxxxxx
1
This is your text...
2
class java.lang.String
3
class [C