代码:

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

相关文章:

  • 2022-01-22
  • 2021-11-22
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
  • 2022-02-17
猜你喜欢
  • 2022-12-23
  • 2021-12-30
  • 2022-01-07
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
相关资源
相似解决方案