如何在Java中不区分大小写的情况下比较两个字符串
该equalsIgnoreCase()方法将该字符串与指定对象进行比较。当且仅当参数不为null并且是一个String对象,表示与此对象相同的字符序列时,结果为true。
示例
public class Sample {
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!!");
boolean retVal;
retVal = Str1.equalsIgnoreCase(Str2);
System.out.println("Returned Value = " + retVal );
retVal = Str1.equalsIgnoreCase( Str3 );
System.out.println("Returned Value = " + retVal );
}
}输出结果
Returned Value = true Returned Value = true
热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话