String toCharArray Method Java Program

Sharing is healthy !!

In the previous post you learnt Char Array to String Java Program. Today we will delve into string tochararray method java program.

This basically converts a string into a character array.

To translate string to character array tochararray() method is used in java.

tochararray method returns new character array with its length same as given string. Let’s see an example,

example: String toCharArray Method Java Program

String toCharArray Method Java Program

public class StringCharArray
{
   public static void main(String[] args)
   {
      String strOriginal = "Flower Brackets";
 
      char arr[];
 
      // using toCharArray() method
 
      arr = strOriginal.toCharArray();
 
      for(int x = 0; x < arr.length; x++)
         System.out.println(arr[x]);
   }
}

Output:

Flower Brackets

Sharing is healthy !!