Java String equalsIgnoreCase() method
equalsIgnoreCase() method compares two Strings based on the their content but ignore the case.
Syntax
public boolean equalsIgnoreCase(Objects anObject)
Parameter
anObject: Object to be compared with the current String without case consideration.
Returns
It returns true when the current String is equivalent to the given String without case consideration Otherwise, it returns false
Java String equalsIgnoreCase() Example1:
public class EqualsIgnoreCaseEx1 { public static void main(String args[]) { String str1,str2,str3; str1="welcome to java tutorial"; str2="WELCOME TO JAVA TUTORIAL"; System.out.println(str2.equalsIgnoreCase(str1)); str3=str2.toLowerCase(); System.out.println(str3.equals(str1)); } }
Output:
true true
Java String equalsIgnoreCase() Example2:
public class EqualsIgnoreCase2 { public static void main(String[] args) { String str = "tutorialandexample"; if(str.equalsIgnoreCase("TUTORIALANDEXAMPLE"))//returns true { String str2=str.concat(".com"); System.out.println(str2); }else System.out.println("something else"); System.out.println(str.equals("TUTORIALANDEXAMPLE"));//returns false } }
Output:
tutorialandexample.com false