Difference between equals method and "==" operator in Java - Interview Question

Both equals() and "==" operator in Java is used to compare objects to check equality but the main difference between equals method and  the == operator is that former is a method and later is an operator. Since Java doesn’t support operator overloading, == behaves identical for every object but equals() is method, which can be overridden in Java and logic to compare objects can be changed based upon business rules. Another notable difference between == and equals method is that former is used to compare both primitive and objects while later is only used for objects comparison. At the same time, beginners struggle to find when to use equality operator (==) and when to use equals method for comparing Java objects. In this tutorial, we will see how equals() method and == operator works in Java and what is the difference between "==" and equals method in Java and finally when to use "==" and equals() to compare objects.
Read more »