The String.Equals () method in the String class in Java:
Source:
public boolean equals (object AnObject) { //if is the same object if (this = = AnObject) { return true; } If the passed in argument is an instance of the String class if (AnObject instanceof String) { String anotherstring = (string) anobject; int n = count;//string length if (n = = anotherstring.count)//If equal length is compared { char v1[] = value;//takes each position character Char v2[] = Anotherstring.value; int i = offset; int j = Anotherstring.offset; while (n--! = 0)//compare { if (v1[i++]! = v2[j++]) return to false for each position ; } return true; } } return false;}
For the Equals () method of the object class, the object that calls the method is not the same object as the object to be compared (the address is judged), and the Equals () method in the String class determines whether the current string is consistent with the contents of the passed-in string.
The Equals () method in the object class:
public boolean equals (Object obj) { //calls the address of the equal object and the address of the parameter object is equal to return (this = = obj);}
Also, for other classes in Java, if you do not override the Equals () method in the object class, we can assume that the Equals () method of invoking the class is to determine whether the two classes are the same class. As long as you use the new class name (), this form of the generated class (except for the single exception), we can think of a different class (address is different).
Implementation code for the String.Equals () method in Java