To convert a string to a char[]
array in Java, you can use the toCharArray
method of the String
class.
Here is an example of how you can convert a string to a char[]
array in Java:
String str = "Hello, World!"; char[] chars = str.toCharArray();
In this example, we have a string called str
that contains the text "Hello, World!". We use the toCharArray
method to convert the string to a char[]
array called chars
.
You can then use the various methods of the char[]
array to perform operations on the characters, such as iterating over the array, searching for a specific character, or modifying the characters.