w3resource logo

Introduction to Java Programming

Java String: toCharArray() Method

Secondary Nav

public char[] toCharArray()

The toCharArray() method converts a given string to a new character array.

Java Platform: Java SE 8

Syntax :


Return Value : a newly allocated character array whose length is the length of this string and whose contents are initialized to contain the character sequence represented by this string.

Return Value Type:

Example : Java String toCharArray() Method

The following example shows the usage of java String() method.

public class Example {

public static void main(String[] args)
        String str = "Python Exercises.";

        // Convert the above string to a char array.
char[] arr = str.toCharArray();
        // Display the contents of the char array.


Python Exercises.

Java Code Editor:

Join our Question Answer community to learn and share your programming knowledge.