Java String equalsIgnoreCase() Method (original) (raw)

Last Updated : 23 Dec, 2024

In Java, **equalsIgnoreCase() method of the String classcompares two strings irrespective of the case (lower or upper) of the string. This method returns a boolean value, true if the argument is not null and represents an equivalent String ignoring case, else false.

**Input: str1 = "pAwAn";
str2 = "PAWan"
**Output: true

**Input: str1 = "piwAn";
str2 = "PAWan"
**Output: false

**Example:

Java `

public class Geeks {

public static void main(String[] args) {
  
    String str1 = "GeeKS FOr gEEks";
    String str2 = "geeKs foR gEEKs";
    String str3 = "ksgee orF geeks";

    // Comparing str1 and str2
    boolean res1 = str2.equalsIgnoreCase(str1);

    System.out.println("str2 is equal to str1 = "+ res1);

    // Comparing str2 and str3
    boolean res2 = str2.equalsIgnoreCase(str3);

    System.out.println("str2 is equal to str3 = "+ res2);
}

}

`

Output

str2 is equal to str1 = true str2 is equal to str3 = false

Syntax:

str2.equalsIgnoreCase(str1);

Here str1 is the string that is supposed to be compared.

**Return Value: A boolean value that is true if the argument is not null and it represents an equivalent String ignoring case, else false.

Internal Implementation

public boolean **equalsIgnoreCase(String str) {
return (this == str) ? true
: (str != null)
&& (str.value.length == value.length)
&& regionMatches(true, 0, str, 0, value.length);
}