Java Data Type Tutorial - Java String.toCharArray()








Syntax

String.toCharArray() has the following syntax.

public char[] toCharArray()

Example

In the following code shows how to use String.toCharArray() method.

import java.util.Arrays;

public class Main {
  public static void main(String[] argv) {
    String str = "java2s.com";
    char[] chars = str.toCharArray();
    System.out.println(Arrays.toString(chars));
  }
}

The output: