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);
自己动手试一试 »
如果您想将 W3Schools 服务用于教育机构、团队或企业,请发送电子邮件给我们
sales@w3schools.com
如果您想报告错误,或想提出建议,请发送电子邮件给我们
help@w3schools.com