Latest web development tutorials

Java equalsIgnoreCase () method

Java String class Java String class


equalsIgnoreCase () method is used to compare the string to the specified object, without regard to case.

grammar

public boolean equalsIgnoreCase(String anotherString)

parameter

  • anObject - the object to compare strings.

return value

If the string is equal to the given object, returns true; otherwise false.

Examples

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

		retVal = Str1.equals( Str2 );
		System.out.println("返回值 = " + retVal );

		retVal = Str3.equals( Str4);
		System.out.println("返回值 = " + retVal );

		retVal = Str1.equalsIgnoreCase( Str4 );
		System.out.println("返回值 = " + retVal );
	}
}

The above program execution results:

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

Java String class Java String class