如何使我的字符串比较不区分大小写?
该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 好听的元旦简短祝福语