In this section, we will learn what the String equalsIgnoreCase() method is and how to use it in Java.
What is Java String equalsIgnoreCase() Method?
The `equalsIgnoreCase()` method compares two string objects to see if they are equal in CONTENT or not.
Basically, this method doesn’t care if both string objects are two independent objects! All that is a matter for this method is the content of the string values!
Note: the `equalsIgnoreCase()` method is NOT case sensitive. For example, a value like `Hello` is the same as the word `HELLO` and `hELLO`.
Java equalsIgnoreCase() Method Syntax:
public boolean equalsIgnoreCase(Object anotherObject)
equalsIgnoreCase() Method Parameters:
This method takes one argument, and that is the string value we want to compare with the string value that the method is invoked with.
equalsIgnoreCase() Method Return Value:
The return value of this method is a Boolean.
If the string values are the same, the result will be true, otherwise it is false.
Example: using String equalsIgnoreCase() method
public class Simple { public static void main(String[] args) { String s1 = new String("Hello to all people out there"); System.out.println(s1.equalsIgnoreCase("Hello to all people")); System.out.println(s1.equalsIgnoreCase("HELLO TO ALL PEOPLE OUT THERE")); } }
Output:
false
true