VOOZH about

URL: https://www.geeksforgeeks.org/java/java-string-equalsignorecase-method-with-examples/

⇱ Java String equalsIgnoreCase() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java String equalsIgnoreCase() Method

Last Updated : 23 Dec, 2024

In Java, equalsIgnoreCase() method of the String class compares two strings irrespective of the case (lower or upper) of the string. This method returns a boolean value, true if the argument is not null and represents an equivalent String ignoring case, else false.

Input: str1 = "pAwAn";
str2 = "PAWan"
Output: true

Input: str1 = "piwAn";
str2 = "PAWan"
Output: false

Example:


Output
str2 is equal to str1 = true
str2 is equal to str3 = false

Syntax:

str2.equalsIgnoreCase(str1);

Here str1 is the string that is supposed to be compared.

Return Value: A boolean value that is true if the argument is not null and it represents an equivalent String ignoring case, else false.

Internal Implementation

public boolean equalsIgnoreCase(String str) {
return (this == str) ? true
: (str != null)
&& (str.value.length == value.length)
&& regionMatches(true, 0, str, 0, value.length);
}

Comment