Why is the same character compared twice by changing its case to UPPER and then to lower?

后端 未结 1 1549
走了就别回头了
走了就别回头了 2021-01-13 06:17

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

相关标签:
1条回答
  • 2021-01-13 06:39

    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

    0 讨论(0)
提交回复
热议问题