Home >>Java String Methods >Java String equalsIgnoreCase() method

Java String equalsIgnoreCase() method

Java String equalsIgnoreCase() method

Java equalsIgnoreCase() method in Java String is used to compares the two given strings based on the string 's content, regardless of the string's case. It is like the method of equals() but does not check the case. When any characters are not matched, they return false otherwise they return true.

Internal implementation

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

Signature

public boolean equalsIgnoreCase(String str)  

Parameter

Str - A different string, that is, compared to this string.

Returns

It returns true if the characters of both strings neglect case equally otherwise false.

String equalsIgnoreCase() method example 1

public class EqualsIgnoreCaseExample
{  
public static void main(String args[])
{  
String n1="PHPTPOINT";  
String n2="phptpoint";  
String n3="PHPTPOINT";  
String n4="java";  
System.out.println(n1.equalsIgnoreCase(n2));
System.out.println(n1.equalsIgnoreCase(n3));  
System.out.println(n1.equalsIgnoreCase(n4));
}
}  

Output
true
true
false
String equalsIgnoreCase Method Example 2

import java.util.ArrayList;  
public class EqualsIgnoreCaseExample2 
{  
    public static void main(String[] args) 
	{  
        String num1 = "Shraddha";  
        ArrayList<String> list = new ArrayList<>();  
        list.add("Ram");   
        list.add("Shraddha ");  
        list.add("Shyam");  
        list.add("ShRaddha kapooR");  
        list.add("Geeta");  
        for (String str : list) 
		{  
            if (str.equalsIgnoreCase(num1)) 
			{  
                System.out.println("Shraddha Kapoor is a clever girl");  
            }  
        }  
    }  
}  

Output
Shraddha Kapoor is a clever girl

No Sidebar ads