On 14 Giu, 10:14, "Mike Schilling" <mscottschill...@hotmail.com>
wrote:
> > Hi, I've read the API description of compareTo method but I don't
> > understand
[quoted text clipped - 4 lines]
> Think about the simplest possible algorithm for determining whether two
> strings are equal, and the difference function it would lead to..
I learned it use lexicographic algorithm ... it mean that if I have:
String s = "a";
String t = "g";
than s.compareTo(t) return -6 because g is far 6 letters from a ....
but why -32 in my examples ???
Dag Sunde - 14 Jun 2007 09:51 GMT
> On 14 Giu, 10:14, "Mike Schilling" <mscottschill...@hotmail.com>
> wrote:
[quoted text clipped - 13 lines]
> than s.compareTo(t) return -6 because g is far 6 letters from a ....
> but why -32 in my examples ???
As someone said... ASCII, ISO-xxx, whatever.
All assigns a numerical position to the characters in the charset.
Take a look at an ASCII table (http://www.asciitable.com/) and count,
and you will see that just like "g" it 6 letters higher that "a",
You will see that "i" is 32 letters higher than "I".

Signature
Dag.
josh - 14 Jun 2007 10:25 GMT
> > On 14 Giu, 10:14, "Mike Schilling" <mscottschill...@hotmail.com>
> > wrote:
[quoted text clipped - 23 lines]
> --
> Dag.
yes I have read an ASCII table in a wrong way!
Robert Klemme - 14 Jun 2007 10:59 GMT
>>> On 14 Giu, 10:14, "Mike Schilling" <mscottschill...@hotmail.com>
>>> wrote:
[quoted text clipped - 20 lines]
>
> yes I have read an ASCII table in a wrong way!
Actually ASCII values do not matte at all here - the exact return value
is just an implementation detail. The important bit is the information
that the return value is less than, equal to or greater than zero which
is mandated by the contract of Comparable.
If you want to know how it's implemented in the case of String you can
look into the sources of the std lib. It's all there.
Kind regards
robert