我有一个字符串
String text = "Good morning. Have a good class. "
+ "Have a good visit. Have fun!";
我把它分开了:
String[] words = text.split("[\\s\\n\\t\\r.,;:!?(){}]");
循环遍历数组得到一个word
word = words[i];
我正在尝试获取单词出现列表。我打印列表,我得到了这个:
[morning:1, class:1, visit:1, fun:1, a:2, good:3, :3, have:3]
**// I have three Obvious empty Strings somewhere ^^ According the :3
所以我添加一个System.out.print(word ", ")
并得到这个:
good, morning, , have, a, good, class, , have, a, good, visit, , have, fun,
// space ^^ space^^ space^^
为什么我会得到这些空格,我该如何纠正?