📌  相关文章
📜  计算字符串中的单词数java代码示例

📅  最后修改于: 2022-03-11 14:52:11.150000             🧑  作者: Mango

代码示例2
String name = "Carmen is a fantastic play"; //arbitrary sentence
        
        int numWords = (name.split("\\s+")).length; //split string based on whitespace
                                                //split returns array - find legth of array
        
        System.out.println(numWords);