equalsIgnoreCase() in Java

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. 

filter_none

edit
close

play_arrow

link
brightness_4
code

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);
  }
}

chevron_right


Output:

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


My Personal Notes arrow_drop_up

pawanasipugmailcom

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.