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

后端 未结 16 2431
余生分开走
余生分开走 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:42

    I already did post this answer somewhere, i will do it here again. This version doesn't use any major inbuilt method. You got the char array, convert it into a String. Hope it helps!

    import java.util.Scanner;
    
    public class SentenceToWord 
    {
        public static int getNumberOfWords(String sentence)
        {
            int counter=0;
            for(int i=0;i

提交回复
热议问题