Java String - equalsIgnoreCase() Method
The Java equalsIgnoreCase() method is used to compare the specified string against the given string. 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 str)
Parameters
str |
specify the string to compare against given string. |
Return Value
Returns true if the specified string is not null and represents a string equivalent to given string ignoring case, else returns false.
Exception
NA.
Example:
In the example below, equalsIgnoreCase() method is used to compare the specified string against the given string.
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 String Methods