From: Wojtek on
Lew wrote :
> 'TimeZone' can easily be a map key, yes, even for a 'TreeMap'.

No it cannot be used as a key. It does not have a 'compareTo' method.

--
Wojtek :-)


From: Lew on
Lew wrote :
>> 'TimeZone' can easily be a map key, yes, even for a 'TreeMap'.
>

Wojtek wrote:
> No it cannot be used as a key. It does not have a 'compareTo' method.
>

Yes, it can be used as a key!
<http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html#TreeMap
(java.util.Comparator)>

The Javadocs are your friend.

--
Lew


From: Eric Sosman on
Wojtek wrote:
> Lew wrote :
>> 'TimeZone' can easily be a map key, yes, even for a 'TreeMap'.
>
> No it cannot be used as a key. It does not have a 'compareTo' method.

It doesn't need one: You can construct a TreeMap with any Comparator
you like. You're not limited to the "natural order" of the keys. See
the `TreeMap(Comparator<? super K> comparator)' constructor.

--
Eric.Sosman(a)sun.com
From: Wojtek on
Lew wrote :
> Lew wrote :
>>> 'TimeZone' can easily be a map key, yes, even for a 'TreeMap'.
>>
>
> Wojtek wrote:
>> No it cannot be used as a key. It does not have a 'compareTo' method.
>>
>
> Yes, it can be used as a key!
> <http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html#TreeMap
> (java.util.Comparator)>
>
> The Javadocs are your friend.

Yes with a separate Comparator. However you cannot do:

TreeMap<TimeZone,String>

directly.

--
Wojtek :-)


From: Lew on
Lew wrote :
>>>> 'TimeZone' can easily be a map key, yes, even for a 'TreeMap'.
>

Wojtek wrote:
> >> No it cannot be used as a key. It does not have a 'compareTo' method.
>

Lew wrote:
>> Yes, it can be used as a key!
>> <http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html#TreeMap
>> (java.util.Comparator)>
>
>> The Javadocs are your friend.
>

Wojtek wrote:
> Yes with a separate Comparator. However you cannot do:
>
> TreeMap<TimeZone,String>
>
> directly.
>

Why doesn't

Map <TimeZone, String> map =
new TreeMap <TimeZone, String> ( new Comparator() { .... } );

work for you?

--
Lew