You can easily count the number of words in a string with the following example:
String words = "One Two Three Four";
int countWords = words.split("\\s").length;
System.out.println(countWords);
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!