HashTables are an un-ordered collection. You can't sort them. What you can do is take values out or take the Map.Entries and put them into an Ordered collection, like a TreeSet that you could then sort with an appropriate Comparator.
Joined: Oct 03, 2007
Could you be more detail i cant get it, is my desired output is possible at all? I REALLY APPRECIATE YOUR HELP.
You can't sort inside the HashTable, so you have to sort outside the table using some sortable collection. You could use a TreeMap which would be analogous to a sorted HashTable, but TreeMaps (and all Maps that I am aware of) sort on the Key, not the Value. So Maps are out.
Your options are then Sets or Lists, and Sets tend to be a better fit to Map data... You have a TreeSet which will provide the Sorting you need, as long as you provide it a Comparator.
So now you need to know what data actually needs to be sorted - the simplest would be to just sort the Values, which you conveniently get out of the HashTable using table.values(). You would then addAll() to the TreeSet and your done.
If you need the Keys to go along for the ride with the sorting then you would need to get the Set of Map.Entrys from the HashTable, easily done using the table.entrySet() method, the results of which you could again addAll() to a TreeSet and be done.
Your key will be to provide a suitable Comparator which knows how to compare the values you enter. [ October 11, 2008: Message edited by: Steve Luke ]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com