I have a method that takes in a list of words. These words are checked against a hASHmap of words that has a String as a key, and an Integer as a value. The String is a word, and the Integer represents that words frequency in a text file.
Currently the list of words are ranked according to their frequency by putting them into a Treemap with the frequency becoming the key.
However, as there can be no duplicate keys, any words with the same frequency value in the Hashmap will not be entered into the Treemap.
What could I do in order to have a date structure that contains the words ranked by their frequency including duplicates?
//given a list of words return a TreeMap of those words ranked by most frequent occurence
private TreeMap rankWords(LinkedList unrankedWords) {
//treemap to automatically sort words by there frequency, making the frequency count the key.
TreeMap<Integer, String> rankedWordsMap = new TreeMap<Integer, String>();
//for each of the words unranked, find that word in the freqMap and add to rankedWords
for (int i = 0; i < unrankedWords.size(); i++) {
if (freqMap.containsKey((String) unrankedWords.get(i))) {
rankedWordsMap.put(freqMap.get((String) unrankedWords.get(i)),
(String) unrankedWords.get(i));
}
}
return rankedWordsMap;
}