split(“ +”) and split(“ ”) are different
问题 I want to erase the vacuum in the String. String input = "java example.java aaa bbb"; String[] temp = input.trim().split(" "); that result is java example.java aaa bbb but i want result that java example.java aaa bbb so, i use the split(" +"). The result is right. but i don't understand, how doing the split(" +"). 回答1: split() takes a regex as it's argument. "+" in regex means "one or more of the previous element". So splitting on " +" will split on "one or more spaces". 回答2: In first case it