by @codeexamples

How to convert a string to char array in Java

Home » java » How to convert a string to char array in Java

To convert a string into a character array we can use the toCharArray() method in Java.

Here is an example:

String name = "codejava";
char [] chArray= name.toCharArray();

for (char value : chArray) {
      System.out.println(value); // printing each character in array
    }
}

Output:

c
o
d
e
j
a
v
a