Java String EqualsIgnoreCase Method

Java String EqualsIgnoreCase Method

Well, in the previously discussed method, we had experienced that even if the content is the same, but the case(upper and lower) is not, the output was coming to be false. In such a condition, if we want to ignore the case, we just have to use the method called as equalsIgnoreCase(), whose name itself says that it ignores the case.

So, let’s now execute the same program which we did previously, just with a changed method this time.

public class StringMethods {
public static void main(String[] args) {
String str1 = “Hello”;
String str2 = new String(“HELLO”);
System.out.println(str1.equalsIgnoreCase(str2));
}
}

Since we used the equalsIgnoreCase() method and then compared two strings, we found that the output is true, which was false previously. So, we can use the equals() method, or the equalsIgnoreCase() method as per the requirements.