equalsIgnoreCase()方法用于将字符串与指定的对象进行比较,不考虑大小写,相等返回true,否则返回false;
而equals()会判断大小写区别。
举例:
public class Test {
public static void main(String args[]) {
String Str1 = new String("abc");
String Str2 = Str1;
String Str3 = new String("abc");
String Str4 = new String("ABC");
boolean retVal;
retVal = Str1.equals( Str2 );
System.out.println("返回值 = " + retVal );
retVal = Str3.equals( Str4);
System.out.println("返回值 = " + retVal );
retVal = Str1.equalsIgnoreCase( Str4 );
System.out.println("返回值 = " + retVal );
}
}
结果:
返回值 = true 返回值 = false 返回值 = true