when the “==” operator is used to compare 2 objects, it checks to see if the objects refer to the same place in memory. In other words, it checks to see if the 2 object names are basically references to the same memory location.
The equals method is defined in the Object class, from which every class is either a direct or indirect descendant. By default, the equals() method actually behaves the same as the “==” operator – meaning it checks to see if both objects reference the same place in memory.
But, the equals method is actually designed to compare the contents of objects, and not their location in memory.
We can override it to get the desired functionality whereby the object contents are compared instead of the object location.
For example, Java String class overrides the equals() method to compare the content of two strings.
Read full article from Java: What's the difference between equals() and ==?
The equals method is defined in the Object class, from which every class is either a direct or indirect descendant. By default, the equals() method actually behaves the same as the “==” operator – meaning it checks to see if both objects reference the same place in memory.
But, the equals method is actually designed to compare the contents of objects, and not their location in memory.
We can override it to get the desired functionality whereby the object contents are compared instead of the object location.
For example, Java String class overrides the equals() method to compare the content of two strings.
Read full article from Java: What's the difference between equals() and ==?