I'm counting how many times the word "world" occurs in a certain file. I've tried to ways: 1)
if (words[i].equalsIgnoreCase("world")) count++;
In this case my program does not find all the instances of "world" in the file. As there are probably words in the file that contain "world" but are not equal to it. 2)
if (words[i].contains("world")) count++;
In this case the program finds too many instances of "world". Again, as there are probably words in the file that contain "world" but are not equal to it. Just in case: when I use equals() instead of equalsIgnoreCase(), the result is the same as in #1. What am I missing?