Here we may learn how to convert a given String object to an array of character in Java.
Source Code
package com.beginner.examples;
public class StringToCharacterArray {
public static void main(String[] args) {
String string= "Hello World";
char[] stringArray;
System.out.println("Before converting to stringArray , string is : " + string);
/*
* To convert string into array use toCharArray() method of string.
*/
stringArray = string.toCharArray();
System.out.print("After converting to stringArray , string is : ");
for(int index=0; index < stringArray.length; index++) {
System.out.print(stringArray[index]);
}
}
}
Output:
Before converting to stringArray , string is : Hello World
After converting to stringArray , string is : Hello World