本文介绍了EqualsIgnoreCase()无法正常工作.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行以下程序时,它只会打印
When i run the following program it prints only
equals says they are equal
但是从Java 8中的equalsIgnoreCase文档中,我们可以得到:
However From equalsIgnoreCase docs in java 8 we have :
public class Test {
public static void main(String[] args) {
String string1 = "abc\u00DF";
String string2 = string1.toUpperCase();
if (string1.equalsIgnoreCase(string2))
System.out.println("equalsIgnoreCase says they are equal");
if (string1.toUpperCase().equals(string2.toUpperCase()))
System.out.println("equals says they are equal");
}
}
所以我的问题是为什么该程序无法打印
So my question is why this program is not printing
equalsIgnoreCase says they are equal
与两个操作一样,使用大写字母.
As in both operations upper case charcters are used.
推荐答案
您正在使用/比较德国ß符号,其大写字母生成 SS ...因此您需要使用 Locale.German
You are using/comparing the german ß sign, its uppercase produce SS... so you need to use the Locale.German
if (string1.toUpperCase(Locale.GERMAN).equals(string2.toUpperCase(Locale.GERMAN)))
将返回true....
that will return true....
这篇关于EqualsIgnoreCase()无法正常工作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!