代码:
String str = "the music made it hard to concentrate";
String delims = "[ ]+";
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
Java 的 String.split 函数,消除空字符串
时间: 2024-10-09 10:37:22