Java String toCharArray() method

Let’s learn java String toCharArray() method.

java String toCharArray() method

Java String toCharArray() method

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

Syntax

public char[] toCharArray()

Return

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.

Also read – java overview

Let’s see a java program,

public class StringToCharArrayDemo
{
   public static void main(String[] args)
   {
      String strOriginal = "Flower Brackets";
      // using toCharArray() method java
      char arr[] = strOriginal.toCharArray();
      System.out.println("Character array : ");
      for(char ch : arr)
      {
         System.out.println(ch);
      }
   }
}


Output:

Character array : Flower Brackets