Tochararray java

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

tochararray java

Description

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

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.

Syntax

public char[] toCharArray()

Returns

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

Also read – char array to string java

Let’s see an example,

public class StringToCharArrayDemo
{
   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:

F
l
o
w
e
r

B
r
a
c
k
e
t
s

Related Posts