Tochararray java

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

tochararray java

Tochararray java

Also Read –¬†Char Array to String Java Program

Description

This method basically converts a string into a character array. To translate string to character array tochararray() method is used in java.

Syntax

public char[] toCharArray()

Returns

tochararray method returns new character array with its length same as given string.

Let’s see an example,

 

Example :

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