Converting a sentence string to a string array of words in Java

后端 未结 16 2462
余生分开走
余生分开走 2020-12-01 00:04

I need my Java program to take a string like:

\"This is a sample sentence.\"

and turn it into a string array like:

{\"this\         


        
16条回答
  •  一个人的身影
    2020-12-01 00:46

    Try using the following:

    String str = "This is a simple sentence";
    String[] strgs = str.split(" ");
    

    That will create a substring at each index of the array of strings using the space as a split point.

提交回复
热议问题