Lower case and upper case letters do have different ASCII values, but they are separated by a constant (42, I think). That is to say, A
is the same distance from a
as B
is from b
as C
is from c
, etc.
ilc
and cli
are different in that they're completely different characters.
compareToIgnoreCase
(or equalsIgnoreCase
) does a character by character comparison. That is, it compares the character at index 0
of str1
to the character at index 0
of str2
. And so on, for every index of the two strings being compared.
If you compare ilc
and cli
, then i
in ilc
is compared to c
in cli
(and they're different), so the comparison returns false
. The comparison doesn't care if i
appears elsewhere in the second string, it only cares if i
or I
exists in the second string at the same index it exists in the first string (and so on for all the rest of the characters, though I imagine it's probably optimized to return false
as soon as it finds one difference).