String numbers = \"5 1 5 1\";
So, is it:
String [] splitNumbers = numbers.split();
or:
String [] spli
You must escape the regex with an additional \ since \ denotes the escape character:
public static void main(String[] args) {
String numbers = "5 1 5 1";
String[] tokens = numbers.split("\\s+");
for(String token:tokens){
System.out.println(token);
}
}
So the additional \ escapes the next \ which is then treated as the literal \.
When using \\s+ the String will be split on multiple whitespace characters (space, tab, etc).