I was looking at code of CaseInsensitiveComparator but could not understand following piece of code
if (c1 != c2) {
c1 = Character.toUpperCase(c1);
c2 = Character.toUpperCase(c2);
if (c1 != c2) {
c1 = Character.toLowerCase(c1);
c2 = Character.toLowerCase(c2);
if (c1 != c2) {
// No overflow because of numeric promotion
return c1 - c2;
}
}
}
What is the purpose of comparing characters in both uppercase and lowercase form? Isn't one of them sufficient? Are we suspecting some characters which can be equal when they are lowercase but not equal when they are uppercase?