Thread: Hi needing help
View Single Post
Old 11-19-2005, 02:03 PM   #3 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,139
Belisarius is on a distinguished road
What you can do is keep Hashtable using words as keys and the value as an Integer, incrementing it each time it's added. Then simply return the values as an array and call a sort using the Array object. Loop through the array and insert the items, in order, into a LinkedList.

A much more cool Java-esque way, however, would be to create a Comparable that contains the String an a count object, overriding equals(), and inserting it into a custom Set that will increment a counter in the Object that's not taken into account in the equals() method. Everytime a String is added to the Set, check to see if it exists, remove it from the Set it if does, increment the counter, and re-add it. The compareTo() would order first on count, then on the String. You could then simply dump it to a LinkedList.
__________________
GitS
Belisarius is offline   Reply With Quote