如何在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 2026祝福语简短创意牛
16 撩妹生日祝福语简短
17 今年节日祝福语简短
18 收围巾的祝福语简短