The purpose of these exercises is to get practice with using some of the
basic data structures. Modyifying the WordFreqency program
in the following proposed exercises is one way to do that.
Around line 104 is the heart of the algorithm. Instead of putting the entries
into an ArrayList and sorting them, they could be put into a TreeSet, which would naturally
sort them. Use the TreeSet constructor that specifies a Comparator
so it knows how to sort them, and add entry set from the HashMap to it.
Then use an iterator to go over the TreeSet..
After you have the previous part running, change the Comparator near the end of the file
to sort by the length of
the word first, and if the lengths are the same, by the frequency.
This should list the entries so that the shortest, most frequent words are last.
You'll need to change the Comparator for this. See line 123...
Copyfree 2004 Fred Swartz - Placed in the public domain.