Skip to content
Related Articles

Related Articles

Java String equalsIgnoreCase() Method with Examples

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 10 Nov, 2021

The equalsIgnoreCase() method of the String class compares 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.

Syntax: 

str2.equalsIgnoreCase(str1);

Note: Here str1 and str2 both are the strings that we need to compare.

Parameters: A string that is supposed to be compared.

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

Illustrations: 

Input : str1 = "pAwAn";
        str2 = "PAWan"
        str2.equalsIgnoreCase(str1);
Output :true
Input : str1 = "powAn";
        str2 = "PAWan"
        str2.equalsIgnoreCase(str1);
Output :false
Explanation: powan and pawan are different strings. 

Note: str1 is a string that needs to be compared with str2.

Example:

Java




// Java Program to Illustrate equalsIgnoreCase() method
 
// Importing required classes
import java.lang.*;
 
// Main class
public class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
 
        // Declaring and initializing strings to compare
        String str1 = "GeeKS FOr gEEks";
        String str2 = "geeKs foR gEEKs";
        String str3 = "ksgee orF geeks";
 
        // Comparing strings
        // If we ignore the cases
        boolean result1 = str2.equalsIgnoreCase(str1);
 
        // Both the strings are equal so display true
        System.out.println("str2 is equal to str1 = "
                           + result1);
 
        // Even if we ignore the cases
        boolean result2 = str2.equalsIgnoreCase(str3);
 
        // Both the strings are not equal so display false
        System.out.println("str2 is equal to str3 = "
                           + result2);
    }
}


Output

str2 is equal to str1 = true
str2 is equal to str3 = false
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!