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

posted @ 2014-07-31 09:52  徐软件  阅读(5134)  评论(0编辑  收藏  举报