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.

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 String_Char_Array {

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

}

}

Output:

Flower Brackets

Sharing is healthy !!