N
nooneinparticular314159
I have an object (say, Car). Car contains some values, one of which
is speed. I want to store lots of cars in some sort of object that
will keep them sorted by speed. Some cars may have the same speed.
The catch is that I want to sort by highest speed, not lowest speed.
If I insert lots of cars into a TreeSet, with the key being the speed,
I get them in increasing order. If there are n cars with the same
speed, I get only one, because the keys are identical. I've been
unable to find an object that would work. I've tried implementing a
compare method in my object, and that doesn't help either. Any ideas?
To summarize, the container object must:
1) Support sorting in inverse order (or another order of my choice)
2) Keep the objects sorted.
3) Support duplicate objects.
(I suppose I could sort on the negative value of the sort key, but...)
Thanks!
is speed. I want to store lots of cars in some sort of object that
will keep them sorted by speed. Some cars may have the same speed.
The catch is that I want to sort by highest speed, not lowest speed.
If I insert lots of cars into a TreeSet, with the key being the speed,
I get them in increasing order. If there are n cars with the same
speed, I get only one, because the keys are identical. I've been
unable to find an object that would work. I've tried implementing a
compare method in my object, and that doesn't help either. Any ideas?
To summarize, the container object must:
1) Support sorting in inverse order (or another order of my choice)
2) Keep the objects sorted.
3) Support duplicate objects.
(I suppose I could sort on the negative value of the sort key, but...)
Thanks!