How to split a String by space

前端 未结 15 1547
傲寒
傲寒 2020-11-22 10:31

I need to split my String by spaces. For this I tried:

str = \"Hello I\'m your String\";
String[] splited = str.split(\" \");

But it doesn\

15条回答
  •  粉色の甜心
    2020-11-22 10:50

    I do believe that putting a regular expression in the str.split parentheses should solve the issue. The Java String.split() method is based upon regular expressions so what you need is:

    str = "Hello I'm your String";
    String[] splitStr = str.split("\\s+");
    

提交回复
热议问题