Mark Raphael Qt wrote:. . . I thought that equals() evaluates the contents of an object and not its memory location . . .
The
equals() method neither evaluates the contents of an object nor its memory location. It provides a definition of equality to be used by objects of the class it is overridden in.
That API page wrote:Indicates whether some other object is "equal to" this one.
If you override the implementation, you can provide your own definition of equality which might include being the same object, having the same state of all the fields, or having the same state
as in some of the fields. Please forget about “memory locations” when programming Java®. It is an object language and memory locations aren't a feature of objects, but there is an
operator which tests whether two references point to the same object. The writer of the class provides the definition by how they write
equals().
If you go through the documentation for Object, String, and StringBuilder, you can see which definitions of equality each uses. That determines the output of the question above.