The javadoc for String.equalsIgnoreCase says:
Two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are equal ignoring case. Two characters c1 and c2 are considered the same ignoring case if at least one of the following is true:
The two characters are the same (as compared by the == operator)
Applying the method Character.toUpperCase(char) to each character produces the same result
Applying the method Character.toLowerCase(char) to each character produces the same result
So can anyone explain this?
public class Test
{
private static void testChars(char ch1, char ch2) {
boolean b1 = (ch1 == ch2 ||
Character.toLowerCase(ch1) == Character.toLowerCase(ch2) ||
Character.toUpperCase(ch1) == Character.toUpperCase(ch2));
System.out.println("Characters match: " + b1);
String s1 = Character.toString(ch1);
String s2 = Character.toString(ch2);
boolean b2 = s1.equalsIgnoreCase(s2);
System.out.println("equalsIgnoreCase returns: " + b2);
}
public static void main(String args[]) {
testChars((char)0x0130, (char)0x0131);
testChars((char)0x03d1, (char)0x03f4);
}
}
Output:
Characters match: false
equalsIgnoreCase returns: true
Characters match: false
equalsIgnoreCase returns: true
java -versionsays1.7.0_03). No, they're not Georgian. One's a Turkish dotless "i" thing and the other has do to with alternative forms of Greek theta. - ajb