Prev: Problems with JTable using fixed rows
Next: is the open sourcing of IntelliJ IDEA getting some love?
From: Wojtek on 3 Nov 2009 10:56 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 3 Nov 2009 11:57 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 3 Nov 2009 12:04 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 3 Nov 2009 13:42 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 3 Nov 2009 14:37
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 |