How to split a String by space

前端 未结 15 1796
傲寒
傲寒 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 11:04

    Use Stringutils.split() to split the string by whites paces. For example StringUtils.split("Hello World") returns "Hello" and "World";

    In order to solve the mentioned case we use split method like this

    String split[]= StringUtils.split("Hello I'm your String");
    

    when we print the split array the output will be :

    Hello

    I'm

    your

    String

    For complete example demo check here

提交回复
热议问题