I'm just trying to think of the best way to go about counting how many time 50'ish different words appear in a document?
I found an example on stackoverflow that was looking for a single word in a document, and it used something like this:
for (String word : words)
{
if(word.equals(stringSearch))
System.out.println("Word was found at position " + indexfound + " on line " + linecount);
}
Is there a similar way to do something like that, but compare the word in the document against every word in the hashset? I don't need to count the occurrence of each word separately, just as long as the word in the doc is any of the keywords.. I can increment the counter. Any help would be appreciated. This homework assignment kinda has me blindsided because we haven't really did anything that involved iterating through a document. So, I'm trying to look up all the info on reading a document, and at the same time figure out my logic for testing each word against the list of words in the set.
All I have so far is an array of the words, then added those to a hashset, and created a variable for the file name (which is passed via command line).
Thanks for any help/insight.


Sign In
Create Account



Back to top









