The below code is in Class String in java. I don\'t understand why the characters from two different strings are compared twice. at first by doing upper case and if
The issue might be more complex.
There are characters, where there are multiple lowercase codepoints for the same uppercase codepoint or vice versa. So to check for case insensitive match, you need to compare both upper and lowercase versions if one of them matches.
One example being
The Greek upper-case letter "Σ" has two different lower-case forms: "ς" in word-final position and "σ" elsewhere.
Source: Wikipedia
For upper case not equal but lowercase very much so, VGR supplied this excellent example:
A better example would be '\u0130' (İ) and 'I'. Passing them through toUpperCase leaves them unchanged (and therefore different), but passing them through toLowerCase results in identical character values