Find the sort method of the Collections class.
Find the Comparator interface and set it up to compare the keys from the Hashtable entries.
Alternatively it is possible to get a Set of the map entries. Check whether you can sort that set by the keys of the entry.
It seems slightly odd that you are putting Hashtables into an ArrayList in the first place.
a TupleList is not a List<Tuple> and can't be made one even with a cast. Internally a TupleList contains a reference to a List<Tuple>, but this is irrelevant. Either you can make your TupleList class implement List<Tuple> or you can sort the internal List<Tuple> by some other means.
On another note, since you are using generics in the rest of your project, you could eliminate the casts in your Comp.compare() method and make it typesafe by changing it to:
[ March 16, 2007: Message edited by: Garrett Rowe ]
Originally posted by Campbell Ritchie:
Have you read the Comparator interface in the API? Work out a way to get it to return 0 if the two objects are "equal" negative number if less and positive number if more. Also implement the "equals" method of Comparator...
Why would it be helpful to override the equals() method here? Normally Comparators that I've used have no state.
I thought there was an equals method in Comparator...
There is but according to the documentation:
Note that it is always safe not to override Object.equals(Object). However, overriding this method may, in some cases, improve performance by allowing programs to determine that two distinct Comparators impose the same order.
I've just never written one where this would be useful.