Since the argument to split()
is a regular expression, you can look for one or more spaces (" +"
) instead of just one space (" "
).
String[] array = s.split(" +");
Since the argument to split()
is a regular expression, you can look for one or more spaces (" +"
) instead of just one space (" "
).
String[] array = s.split(" +");