So far, i have figured out how to get all the words to show, alongside the number which indicates how many times each unique word appears in the text. However, i cannot figure out how to get another list which displays all the unique words that ONLY occur 4 or more times. Any idea on how i can achieve this because i think i have done the hard bit here, but i would just like to know how i can get this next part.
Assuming that you are using Java 8, you can filter the entries in the
countOcc map as follows based on the number of occurrences in the text. Finally, I have printed the filtered results.
countOcc.entrySet().stream() .filter(entry->entry.getValue()>=4) .forEach(entry->System.out.println(entry.getKey()))