Another way to crop this is to use a look ahead and look to make sure that the space is sandwiched between two characters without space, ... something like:
String[] arr = str.split("(?<=\\S)\\s+(?=\\S)");
The problem is that it does not clip the leading spaces, giving this result:
a b
but it should not be used as String#split(...) for splitting, not for trimming.
Hovercraft full of eels
source share