Java字符串equalsIgnoreCase()方法示例。
String类的equalsIgnoreCase()方法将此String与另一个String进行比较,而忽略大小写考虑。如果两个字符串的长度相同,并且两个字符串中的对应字符为相等的忽略大小写,则认为它们相等。
示例
import java.lang.*; public class StringDemo { public static void main(String[] args) { String str1 = "sachin tendulkar"; String str2 = "amrood admin"; String str3 = "AMROOD ADMIN"; //检查大小写是否相等 boolean retval1 = str2.equalsIgnoreCase(str1); boolean retval2 = str2.equalsIgnoreCase(str3); //打印返回值 System.out.println("str2 is equal to str1 = " + retval1); System.out.println("str2 is equal to str3 = " + retval2); } }
输出结果
str2 is equal to str1 = false str2 is equal to str3 = true