Split Strings in java by words

后端 未结 8 1610
迷失自我
迷失自我 2020-12-16 06:06

How can I split the following word in to an array

That\'s the code

into

array
0 That
1 s
2 the
3 code

I tried

8条回答
  •  盖世英雄少女心
    2020-12-16 06:51

    You can split according to non-characters chars:

    String str = "That's the code";
    String[] splitted = str.split("[\\W]");
    

    For your input, output will be:

    That
    s
    the
    code
    

提交回复
热议问题