Splitting a string with multiple spaces

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(" +");

Leave a Comment