Re: Sort Map on Value
Andreas Leitgeb wrote:
Lew <noone@lewscanon.com> wrote:
Andreas Leitgeb wrote:
Joshua Cranmer <Pidgeot18@verizon.invalid> wrote:
I believe the TreeMap would be calling the compare function in looking
up a key, so you'd need a different map to back the lookup.
Why that? Isn't the lookup by key still hashCode()/equals()-based?
Maybe indeed I'd need a different map for lookup, but then more likely
because during a put()-operation it will need compare() and by that
time, we might find the TreeMap in an inconsistent state for a get().
<http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html>
... the Map interface is defined in terms of the equals operation,
but a map performs all key comparisons using its compareTo (or
compare) method, ...
And that after I believed to know all the Maps by heart already...
I stand corrected.
I'm pretty sure that the business about using 'compare[To]()' applies only to
SortedMaps.
--
Lew