The list of methods to do Word Count are organized into topic(s).
int
countWords(String segment, char[] wordDelimiters) Count Words
int wordCount = 0;
boolean lastWasGap = true;
for (int i = 0; i < segment.length(); i++) {
char ch = segment.charAt(i);
boolean isDelimiter = false;
for (int j = 0, isize = wordDelimiters.length; j < isize; j++) {
if (ch == wordDelimiters[j]) {
isDelimiter = true;
...
int
countWords(String str) count Words
if (str.equals("") || str == null) {
return 0;
int numberSpaces = 0;
for (char c : str.toCharArray()) {
if (c == ' ') {
numberSpaces++;
return ++numberSpaces;
int
countWords(String str) Returns the number of "words" in a given string.
return str.trim().split(" ").length;