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 and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- Java | ==, equals(), compareTo(), equalsIgnoreCase() and compare()
- Java.Lang.Float class in Java
- Java.lang.Character Class in Java
- Java.lang.Number Class in Java
- Java.lang.Boolean Class in Java
- Java.Lang.Double class in Java
- Java.Lang.Byte class in Java
- Java.Lang.Short class in Java
- Java.lang.Integer class in Java
- Java.Lang.Long class in Java
- Java.lang.Class class in Java | Set 1
- Java.lang.Enum Class in Java
- Java.lang.Class class in Java | Set 2
- Java.util.PriorityQueue class in Java
- Java.lang.Character.Subset Class in Java
- Java.lang.Math Class in Java | Set 1
- Java.lang.Math Class in Java | Set 2
- Java.lang.Character.UnicodeBlock Class in Java
- Java.lang.Void Class in Java
- Java.lang.Compiler Class in Java
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.

