In my method, my objective is to store the words in a string into a HashMap. They key will be a word and the result will be the number of times the word occurs.
So far I have attempted the search portion, however, for the part where I increment I left it to just print yes because I have not figured out how to do that either.
So far I am just hoping for the program to print yes for the number of times there is a repeat, however, I am getting an exception for my if statement.
public void countWord(){
String tokens[] = userInput.trim().replaceAll("\\s+", " ").split(" ");
for(int i = 0; i < tokens.length; ++i) {
if(bow.containsKey(tokens[i])) {
System.out.printf("yes\n");
}
else {
bow.put(tokens[i], 1);
}
}
}
I'm assuming bow.containsKey(tokens[i]))
is improper syntax and I was wondering how I could replace that.