Re: How to check variables for uniqueness ?
- From: John Ersatznom <j.ersatz@xxxxxxxxxxxxxxx>
- Date: Thu, 18 Jan 2007 17:56:15 -0500
Chris Uppal wrote:
It depends on what you mean. String.length() returns, correctly, the number of
Java "char"s in the String. No problem there. What /is/ a problem is that
that is not the same as the number of characters in the Unicode text. That's a
problem caused by the mis-specification of Java's chars to be 16-bit
quantities. It is highly unfortunate, but there is very little that can be
done about it now. It means that correct programming is more difficult than it
looks, and also more difficult than it /should/ be. There is nothing in the
problem space that makes this difficult (well, actually there is, but we'll
pretend there isn't for now[*]), it's not an /inherently/ complex problem, but
historical mistakes in Java's design mean that the API mostly works in terms of
UTF-16 encoding (sequences of 16-bit values) rather than in terms of real
Unicode characters.
Returning to the original context of this discussion, I repeat my assertion that it also /should/ be simple to use strings as map keys, and to do so case-insensitively if you so desire. AFAICT, in fact, using toUpperCase might be the way to do it, avoiding equalsIgnoreCase and toLowerCase. The weird German word with the untypable character becomes "BEISSEN" and so presumably does "beissen", so all variations on that become one key value. I guess x.toUpperCase().equals(y.toUpperCase()) has to be used as the "real" equalsIgnoreCase() then. And to get a canonical lower case form, x.toUpperCase().toLowerCase(), which will turn any spelling of that same word into "beissen". That becomes the "real" toLowerCase() then.
:P
.
- Follow-Ups:
- Re: How to check variables for uniqueness ?
- From: Oliver Wong
- Re: How to check variables for uniqueness ?
- From: Lew
- Re: How to check variables for uniqueness ?
- References:
- Re: How to check variables for uniqueness ?
- From: John Ersatznom
- Re: How to check variables for uniqueness ?
- From: Oliver Wong
- Re: How to check variables for uniqueness ?
- From: John Ersatznom
- Re: How to check variables for uniqueness ?
- From: Oliver Wong
- Re: How to check variables for uniqueness ?
- From: John Ersatznom
- Re: How to check variables for uniqueness ?
- From: Lew
- Re: How to check variables for uniqueness ?
- From: John Ersatznom
- Re: How to check variables for uniqueness ?
- From: Chris Uppal
- Re: How to check variables for uniqueness ?
- From: John Ersatznom
- Re: How to check variables for uniqueness ?
- From: Chris Uppal
- Re: How to check variables for uniqueness ?
- Prev by Date: Re: How to check variables for uniqueness ?
- Next by Date: Re: How to check variables for uniqueness ?
- Previous by thread: Re: How to check variables for uniqueness ?
- Next by thread: Re: How to check variables for uniqueness ?
- Index(es):
Relevant Pages
|