The equals() method checks if some other object passed to it as an argument is equal to the object on which this method is invoked. The default implementation of the equals() method is in the Object class, the mother of all classes in Java. The equals() method in the Object class checks if two object references refer to the same object, i.e., it checks the referential equality of the two object references. This comparison is also known as shallow comparison.

Other classes in Java provide their own implementation of the equals() method. The classes providing their own implementations of the equals() method perform a deep comparison, i.e., the equals() method in these classes checks if the values of the objects are the same.

  • Share/Bookmark