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.
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
filter_none
Output:
str2 is equal to str1 = true str2 is equal to str3 = false
Recommended Posts:
- Java | ==, equals(), compareTo(), equalsIgnoreCase() and compare()
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.concurrent.Phaser class in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.util.concurrent.RecursiveTask class in Java with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.function.LongPredicate interface in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.function.BiPredicate interface in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
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.



