Count Number of Words in a String
Counting the number of words in a string can be achieved easily with the following example:
Example
String words = "One Two Three Four";
int countWords = words.split("\\s").length;
System.out.println(countWords);
|