Java 如何统计单词数量
统计字符串中单词的数量
您可以使用以下示例轻松地统计字符串中单词的数量
示例
String words = "One Two Three Four";
int countWords = words.split("\\s").length;
System.out.println(countWords);
自己尝试一下 »
您可以使用以下示例轻松地统计字符串中单词的数量
String words = "One Two Three Four";
int countWords = words.split("\\s").length;
System.out.println(countWords);
自己尝试一下 »
If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]
If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]