This Java program shows how you can convert String to char array in Java. In 
Java String class there is a method toCharArray() that is used for the purpose. 
This method returns a character array whose length is the length of this string and the array is initialized to contain the character sequence represented 
by this string.
Convert String to char[] in Java
public class StringToCharArray {
 public static void main(String[] args) {
  String str = "Test String";
  // Converting to char array
  char[] charArray = str.toCharArray();
  // Accessing each character
  for(Character c : charArray)
   System.out.println(c);
 }
}
Output
T e s t S t r i n g
That's all for this topic Converting String to Char Array in Java. If you have any doubt or any suggestions to make please drop a comment. Thanks!
>>>Return to Java Programs Page
Related Topics
You may also like-
No comments:
Post a Comment