String toCharArray Method Java Program

Hey guys!! Welcome to flower brackets blog. Today we will delve into string tochararray method java program.

In the previous post you learnt Char Array to String 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,

String toCharArray Method Java Program

Example: 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

You May Also Like