Java String equalsIgnoreCase()

The syntax of the string equalsIgnoreCase() method is:

string.equalsIgnoreCase(String str)

Here, string is an object of the String class.


equalsIgnoreCase() Parameters

The string equalsIgnoreCase() method takes a single parameter.

  • str - the string to be compared

equalsToIgnoreCase() Return Value

  • returns true if the strings are equal, ignoring case considerations
  • returns false if the strings are not equal
  • returns false if the str argument is null

Example 1: Java String equalsIgnoreCase()

Here,

  • str1 and str2 are equal if you do not consider case differences. Hence, str1.equalsIgnoreCase(str2) returns true.
  • str1 and str3 are not equal. Hence, str1.equalsIgnoreCase(str3) and str3.equalsIgnoreCase(str1) returns false.

Example 2: Check if Two Strings are Equal

Output

str1 and str2 are equal

If you need to compare two strings with case differences taken into consideration, use either