secret said:
It's all about the underlying collection you use. You want to use a
SortedMap, the only one of which (that I'm aware of) is the TreeMap. That
should sort you out. Of course you should also stop using an enumberation
and join the world of Java 2 with iterators!
Hope that helps.
alan
A SortedMap is of no help if you want to sort on the values in the Map.
SortedMaps are sorted on the keys.
You will need to put the information in a temporary array or collection
and sort it there. There are several ways to do this, but if you want
to retain the ID and associated value as a unit then you will probably
find it easiest to work with the Map.Entry objects obtained from your
Hashtable's entrySet(). You will need to write a Comparator that
defines the appropriate ordering of the Map.Entry objects, based on
their value objects. You then have three main options:
(1) obtain an array of the map entries by means of the entry set's
toArray() method, and sort that using Arrays.sort(Object[], Comparator);
(2) construct a List populated with the map entries and sort that using
Collections.sort(List, Comparator); or
(3) construct a SortedSet based on your Comparator and containing the
map entries.
If all were equal I'd do (1).
John Bollinger
(e-mail address removed)