Quick example:
public class Test { public static void main(String[] args) { String str = \" a b\"; String[] arr = str.split(\"\\\\s+\")
Instead of trimming, you could just add an if to check if a string is empty or not.