Java String toCharArray()

The syntax of the toCharArray() method is:

string.toCharArray()

Here, string is an object of the String class.


toCharArray() Parameters

The toCharArray() method doesn't take any parameters.


toCharArray() Return Value

  • returns a char array

Example: Java String toCharArray()

class Main {
  public static void main(String[] args) {
    String str = "Java Programming";

    // creating a char array
    char[] result;

    result = str.toCharArray();
    System.out.println(result); // Java Programming
  }
}

Here, the length of the char array result will be equal to the length of the string str.


Also Read:

Did you find this article helpful?

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community