Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
"Baum".equalsIgnoreCase("BAUM") liefert true."Baum".equalsIgnoreCase("BAUM") liefert true.Die Verwendung vonman kann auchliefertJava:"aBc".toLowerCase().equals("abc")wenn du kein equalsIgnoreCase() verwenden willst.Java:true
equalsIgnoreCase und toLowerCase().equals muss nicht zum gleichen Ergebnis führen: final String s1 = "" + (char) 73; //LATIN CAPITAL LETTER I
final String s2 = "" + (char) 304; //LATIN CAPITAL LETTER I WITH DOT ABOVE
System.out.println(String.format("s1: %s%ns2: %s", s1, s2));
System.out.println(String.format("s1.equalsIgnoreCase(s2): %s", s1.equalsIgnoreCase(s2)));
System.out.println(String.format("s1.toLowerCase().equals(s2.toLowerCase()): %s", s1.toLowerCase().equals(s2.toLowerCase())));
s1: I
s2: İ
s1.equalsIgnoreCase(s2): true
s1.toLowerCase().equals(s2.toLowerCase()): false
Ja, das liegt einfach daran, dass hier die Definition ist, dass die Codepoints einzeln verglichen werden.Die Verwendung vonequalsIgnoreCaseundtoLowerCase().equalsmuss nicht zum gleichen Ergebnis führen
Two strings are considered equal ignoring case if they are of the same length and corresponding Unicode code points in the two strings are equal ignoring case.
Two Unicode code points are considered the same ignoring case if at least one of the following is true:
- The two Unicode code points are the same (as compared by the == operator)
- Calling Character.toLowerCase(Character.toUpperCase(int)) on each Unicode code point produces the same result
final String s2 = "" + (char) 304; //LATIN CAPITAL LETTER I WITH DOT ABOVE
System.out.println(s2.toLowerCase().length()); // 2
System.out.println(s2.toLowerCase().codePointAt(0)); // 105
System.out.println(s2.toLowerCase().codePointAt(1)); // 775
Note that this method does not take locale into account, and will result in unsatisfactory results for certain locales. The Collator class provides locale-sensitive comparison.