I have a large text file I am reading from and I need to find out how many times some words come up. For example, the word the. I\'m doing this line by line e
Splitting the Strings sounds like a lot of overhead just to find out the number of occurrences in a file. You could use String.indexOf(String, int) to recursively go through the whole line/file, like this:
int occurrences = 0;
int index = 0;
while (index < s.length() && (index = s.indexOf("the", index)) >= 0) {
occurrences++;
index + 3; //length of 'the'
}