• Home
  • Recent Q&A
  • Java
  • Cloud
  • JavaScript
  • Python
  • SQL
  • PHP
  • HTML
  • C++
  • Data Science
  • DBMS
  • Devops
  • Hadoop
  • Machine Learning
in JAVA by
Can you tell the difference between equals() method and equality operator (==) in Java?

1 Answer

0 votes

equals()                                                                    Equally Operator (==)

This is a method defined in the Object class. It is a binary operator in Java.

This method is used for checking the equality
of contents between two objects as per the
specified business logic.                                          This operator is used for comparing addresses (or references), i.e checks if both the objects are pointing to the same memory location.


In the cases where the equals method is not overridden in a class, then the class uses the default implementation of the equals method that is closest to the parent class.

Object class is considered as the parent class of all the java classes. The implementation of the equals method in the Object class uses the == operator to compare two objects. This default implementation can be overridden as per the business logic.

Related questions

0 votes
asked Jun 16, 2019 in JAVA by reins.robin
0 votes
asked Jun 30, 2020 in Python by GeorgeBell