//equals 在比较字符串时大小写敏感,equalslgnoreCase 在比较字符串相等时会忽略大小写,isEmpty是字符串的判空判断
package com.test.simple;
public class TestEqualForStr {
public static String str1 = "iuserdomain";
public static String str2 = "IUSERDOMAIN";
public static boolean testEquals(String s1, String s2){
boolean isTrue = s1.equals(s2);
return isTrue;
}
public static boolean testEqualsIgnoreCase(String s1, String s2){
boolean isTrue = s1.equalsIgnoreCase(s2);
return isTrue;
}
public static boolean testIsEmpty(String s1){
boolean isTrue = s1.isEmpty();
return isTrue;
}
public static void main(String str[]){
System.out.println(testEquals(str1, str2));
System.out.println(testEqualsIgnoreCase(str1, str2));
System.out.println(testIsEmpty(""));
}
}
false
true
true
本文介绍了Java中字符串比较的方法,重点对比了equals与equalsIgnoreCase的区别。equals方法在比较时区分大小写,而equalsIgnoreCase则不区分大小写。此外,还介绍了判断字符串是否为空的方法。
3004

被折叠的 条评论
为什么被折叠?



