How do I count the number of words in a string?

后端 未结 8 1661
感情败类
感情败类 2021-01-13 02:54

I need to count the number of words and I am assuming the correct way to do it is by calculating the number of times that the previous character in a string is not a letter

8条回答
  •  情深已故
    2021-01-13 03:15

    Use just like this

    String s = "I am Juyel Rana, from Bangladesh";
    int count = s.split(" ").length;
    

提交回复
热议问题