Let's say that you have overridden an object's equals() and hashCode() methods, so that they use the object's fields.
How you do you check if two references are to the same object, ala the stock equals() method?
Use ==
on objects to perform identity comparison.
That is what the default implementation of equals()
does, but one normally overrides equals()
to serve as an "equivalent content" check.
The default bahaviour of equals() is to compare the two objects using the == operator. So if you want the default bahaviour use ==, if you want your overridden behaviour use equals().
use == Operator because it compares with the reference not with the content, if u want to compare with content u can use equals() method.