Facebook Page Twitter Page LinkedIn Page
× Java Tutorial Java Advanced Java Resources


The Java string toCharArray() method is used to return a character array containing all characters of the string.

Syntax

public char[] toCharArray()

Parameters

No parameter is required.

Return Value

Returns a character array containing all characters of the string.

Example:

In the below example, toCharArray() method is used to return a character array containing all characters of the given string.

public class MyClass {
  public static void main(String[] args) {
    String MyString = "HELLO";
    char[] Arr = MyString.toCharArray();
    
    for(int i = 0; i < Arr.length; i++)
      System.out.print(Arr[i] + " ");
  }
}

The output of the above code will be:

H E L L O

❮ Java String Methods