Re: Sorting TimeZone
Wojtek wrote:
Lew wrote :
Lew wrote:
Oops. Naturally I meant to write
Map <TimeZone, String> map =
new TreeMap <TimeZone, String> ( new Comparator <TimeZone> ()
{ .... } );
No arguments that this does work.
However I was replying to your statement "'TimeZone' can easily be a map
key, yes, even for a 'TreeMap'. " which appears to say that you do not
need a custom Comparator:
The natural order and comparator behaviors are equally valid. Throughout
the TreeMap documentation, unqualified statements apply to both cases.
Statements that only apply to the natural order case say so. Given the
way the TreeMap documentation is written, I would not assume a natural
order TreeMap is meant unless the writer says so.
I think it is a mistake to treat a Comparable key type as the proper way
to use TreeMap or TreeSet, and a specified Comparator as somehow weird
or "indirect". It can create a mental block to what is often the best
choice for a sorted set or sorted map implementation, when either the
key type does not implement Comparable, or the required order is not its
Comparable order.
Patricia