扫码一下
查看教程更方便
equalsIgnoreCase() 方法将此字符串与另一个字符串进行比较,忽略大小写。 如果两个字符串的长度相同,并且两个字符串中对应的字符不区分大小写,则认为它们相等。
public boolean equalsIgnoreCase(String anotherString)
anotherString - 与此 String 进行比较的字符串。
如果参数不为 null 且字符串相等,则此方法返回 true,忽略大小写; 否则为假。
public class Main { public static void main(String args[]) { String Str1 = new String("This is really not immutable!!"); String Str2 = Str1; String Str3 = new String("This is really not immutable!!"); String Str4 = new String("This IS REALLY NOT IMMUTABLE!!"); boolean retVal; retVal = Str1.equals( Str2 ); System.out.println("Returned Value = " + retVal ); retVal = Str1.equals( Str3 ); System.out.println("Returned Value = " + retVal ); retVal = Str1.equalsIgnoreCase( Str4 ); System.out.println("Returned Value = " + retVal ); } }
上面示例编译运行结果如下
Returned Value = true
Returned Value = true
Returned Value = true