Java String - equalsIgnoreCase() Method
The java.lang.String.equalsIgnoreCase() method is used to compare the specified string against the given string, ignoring case considerations. It returns true if the specified string is not null and represents a string equivalent to given string ignoring case, else returns false.
Syntax
public boolean equalsIgnoreCase(String anotherString)
Parameters
anotherString |
Specify the string to compare against given string. |
Return Value
Returns true if the argument is not null and it represents an equivalent String ignoring case; false otherwise.
Exception
NA.
Example:
In the example below, equalsIgnoreCase() method is used to compare the specified string against the given string.
import java.lang.*; public class MyClass { public static void main(String[] args) { String str1 = "Hello"; String str2 = "HELLO"; String str3 = "World"; System.out.println(str1.equalsIgnoreCase(str2)); System.out.println(str1.equalsIgnoreCase(str3)); } }
The output of the above code will be:
true false
❮ Java.lang - String