How can you use collators with the JDK Collections such as!_NEWLINE_!HashMap, which are hard-coded to use equals()?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Christopher_Moran
Posted On:   Thursday, April 26, 2001 06:18 PM

The i18n recommendation for performing locale-sensitive string comparisons is to use a Collator, and not rely on the equals() implementation in String, because, among other things, a Collator can correctly decompose Unicode characters. My question is: given that a Collator and equals() have different notions of equality, how can one use the Collections classes such as SortedMap or TreeSet? Those classes require the comparator (i.e. Collator) and equals() to operate identically so that the Collection can properly implement the Map/Set interface. What's more, how can one use even a simple HashMap with Strings as keys, when the get() implementation in HashMap uses an equals(), an   More>>

The i18n recommendation for performing locale-sensitive
string comparisons is to use a Collator, and not rely on the
equals() implementation in String, because, among other
things, a Collator can correctly decompose Unicode characters.
My question is: given that a Collator and equals() have
different notions of equality, how can one use the Collections
classes such as SortedMap or TreeSet? Those classes
require the comparator (i.e. Collator) and equals() to operate
identically so that the Collection can properly implement the
Map/Set interface. What's more, how can one use even a simple
HashMap with Strings as keys, when the get() implementation
in HashMap uses an equals(), and has no ability to use
comparators?

   <<Less

Re: How can you use collators with the JDK Collections such as!_NEWLINE_!HashMap, which are hard-coded to use equals()?

Posted By:   Alistair_Sheffield  
Posted On:   Thursday, May 17, 2001 09:15 AM

I suspect you might be the same person who posted a message on Sun's I18n Forum, but if not (and for anyone else reading this), take a look at the answers I and others gave there:
http://forum.java.sun.com/read/16805306/qAXnGMUDgA-EAAZBP


Alistair

About | Sitemap | Contact