Question:
Is there an easy way to import a string into an array of chars?
Answer:
Use the String method toCharArray().
Code:
public class StringToArray { public static void main(String args[]){ String str = "Hello World"; char[] array; array = str.toCharArray(); for(int i=0; i < array.length; i++){ System.out.println(array[i]); } } }
Output:
$ java StringToArray H e l l o W o r l d