Skip to content
Related Articles

Related Articles

equalsIgnoreCase() in Java
  • Difficulty Level : Basic
  • Last Updated : 04 Dec, 2018

The equalsIgnoreCase() method compares two strings irrespective of the case (lower or upper) of the string. This method returns true if the argument is not null and it represents an equivalent String ignoring case, else false.

Syntax:

str2.equalsIgnoreCase(str1);
Here str1 and str2 both are the strings which we need to compare.

Parameters:

str1: This is a string which needs to be compared.

Return:

This method returns true if the argument is not null and it represents an 
equivalent String ignoring case, else false.

Examples:



Input : str1 = "pAwAn";
        str2 = "PAWan"
        str2.equalsIgnoreCase(str1);
Output :true

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




import java.lang.*;
  
public class GFG {
  
  public static void main(String[] args) {
    String str1 = "GeeKS FOr gEEks";
    String str2 = "geeKs foR gEEKs";
    String str3 = "ksgee orF geeks";
  
    // if we ignore the cases both the strings are equal.
    boolean result1 = str2.equalsIgnoreCase(str1);
    System.out.println("str2 is equal to str1 = " + result1);
  
    // even if ignoring the cases both the strings are not equal.
    boolean result2 = str2.equalsIgnoreCase(str3);
    System.out.println("str2 is equal to str3 = " + result2);
  }
}

Output:

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

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :