Java 的 String.split 函数,消除空字符串
代码:
1 String str = "the music made it hard to concentrate"; 2 String delims = "[ ]+"; 3 String[] tokens = str.split(delims);
结果为:
the, music, made, it, hard, to, concentrate
原因:
String.split(String regex):参数是一个正则表达式
转自:http://pages.cs.wisc.edu/~hasti/cs302/examples/Parsing/parseString.html