Java equals () method
equals () method is used to compare the string to the specified object.
grammar
public boolean equals(Object anObject)
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"); boolean retVal; retVal = Str1.equals( Str2 ); System.out.println("返回值 = " + retVal ); retVal = Str1.equals( Str3 ); System.out.println("返回值 = " + retVal ); } }
The above program execution results:
返回值 = true 返回值 = true