Posted By:
Jani_Kaarela
Posted On:
Thursday, January 13, 2005 06:05 AM
I am having a hashset it contains object.In that object their is a Count variable on which we can make calculations.we can get the value of count by classname.getCount method.So now i want to sort that hashtable on the basis of value of the count
I haven't got much experience on this particular kind of computing problem, but I think I know a suitable solution...
Instead of a HashSet, use TreeSet. By default, it uses "natural ordering", ie. as ordered using Comparable. It has a constructor which accepts a Comparator. Implement a Comparator that compares your objects' count value and pass it to the constructor.
You contradict yourself in your problem description: first, you say you're using a HashSet, then later you say it's a Hashtable. Which one is it? The above solution only applies to a SortedSet, since a SortedMap is sorted by it's keys, not values!