I want to parse user input in to individual characters. For example, the input
Hello! My name is x
Should be split in:
{"H", "e", "l", "l", "o", "!"," ", "M","y"....}
Note that I want to keep the whitespace.
I can't seem to figure out how to do this using String.split. I've tried searching for regex that would do this but all of them cut off at !.
This is the current code, I'm trying to split the string coming in from the scanner.
public static List<String> getUserInput() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a line of text: ");
return Arrays.asList(scanner.next().split(""));
}
Any help is appreciated!