Sorting using 2 parameters

Hello,

I have a collection of objects which need to be sorted based on 2 parameters. One param is priority and the other is time. I need to sort this collection based on priority first. Every priority in turn could have a smaller collection which will be sorted based on time.

All I could think was to separate the initial collection into separate ones and implement comparable on each one in turn so that they are sorted based on the time.....

Any better way to do this folks?

Many thanks in advance

[532 byte] By [Lexus316a] at [2007-11-27 8:01:54]
# 1
The easiest way is to implement Comparable, or write a Comparator, to satisfy your requirements. The basis of the code would be something like this:if this.priority = that.priority then return comparison(this.time, that.time) else return comparison(this.priority,
DrClapa at 2007-7-12 19:44:01 > top of Java-index,Core,Core APIs...
# 2
Many thanks for the reply. It seems to work ok!Cheers
Javabuga at 2007-7-12 19:44:01 > top of Java-index,Core,Core APIs...