String numbers = \"5 1 5 1\";
So, is it:
String [] splitNumbers = numbers.split();
or:
String [] spli
In your above case split("\s+");
, you need to escape \ with another backslash, which is:
split("\\s+");
Or
split(" ");
also can do it
Note that split("\\s+");
split any length of whitespace including newline(\n
), tab(\t
) while split(" ");
will split only single space.
For example, when you have string separated with two spaces, say "5 1 5 1" ,
using split("\\s+");
you will get {"5","1","5","1"}
while using split(" ");
you will get {"5","","1","5","1"}