I'm counting the occurrence of a word in a linked list using the Collections.frequency, however because It is in a for loop it reprints the occurrence depending on how many times it finds the word.
For example if i add "test" twice to the list, and print the occurrence it would print
test:2
test:2
Do I need to move it outside the for loop or something?
String word = textField.getText().toLowerCase();
for(String y : wordList) {
if(y.contains(word)) {
System.out.println(y + " Occured: " + Collections.frequency(wordList,y) + " times");
}
}
But I want to keep the use of a LinkedList without a set