Java equalsIgnoreCase() Method

Java String类Java String Class


The equalsIgnoreCase() method is used to compare the string with the specified object, ignoring case differences.

Syntax

public boolean equalsIgnoreCase(String anotherString)

Parameters

  • anObject-- The object to be compared with the string.

Return Value

Returns true if the given object is equal to the string, otherwise returns false.

Example

equals() checks case differences, while equalsIgnoreCase() does not:

Example

public class Test {
    public static void main(String args[]) {
        String Str1 = new String("example");
        String Str2 = Str1;
        String Str3 = new String("example");
        String Str4 = new String("EXAMPLE");
        boolean retVal;

        retVal = Str1.equals( Str2 );
        System.out.println("Return value = " + retVal );

        retVal = Str3.equals( Str4);
        System.out.println("Return value = " + retVal );

        retVal = Str1.equalsIgnoreCase( Str4 );
        System.out.println("Return value = " + retVal );
    }
}

The output of the above program is:

返回值 = true
返回值 = false
返回值 = true

Java String类Java String Class

Other Extensions