In Java, the Equals method is defined in the object class, and the Equals method in the object class is the source code, as you can see from the source code that the Equals method in the object class is used to return to determine whether two objects point to the same address
public boolean equals (Object obj) {
return (this = = obj);
}
The Equals method in the Ojbect class overrides the quilt class, for example, string overrides the Equals method, and the Equals method of string has the following source code,
public boolean equals (Object anobject) {
Determines whether two objects point to the same address, and if it points to the same address, it must be the same object and the object values are consistent
if (this = = AnObject) {
return true;
}
Returns False if the Parameter object is not a string data type, otherwise compares two string values, returns True if all equals, otherwise returns false
if (anobject instanceof String) {
String anotherstring = (string) anobject;
int n = value.length;
if (n = = anotherString.value.length) {
Char v1[] = value;
Char v2[] = Anotherstring.value;
int i = 0;
while (n--! = 0) {
if (v1[i]! = V2[i])
return false;
i++;
}
return true;
}
}
return false;
}
Java Equals method detailed