The toCharArray() method in Java converts a string into a character array. It receives a string as argument and returns a character array containing the characters in the string.
##In JavatoCharArray() Usage
toCharArray() is a method of the
String class in Java, used to convert a string into a character array.
Usage:
<code class="java">char[] charArray = string.toCharArray();</code>
string is the string to be converted,
charArray is the converted character array .
Example:
<code class="java">String str = "Hello World"; char[] charArray = str.toCharArray(); System.out.println(Arrays.toString(charArray));</code>
<code>[H, e, l, l, o, , W, o, r, l, d]</code>
Note:
, a
NullPointerException exception will be thrown.
The above is the detailed content of Usage of tochararray in java. For more information, please follow other related articles on the PHP Chinese website!