Both equals() and "==" operator in Java is used to compare objects to check equality but main difference between equals method and == operator is that former is method and later is 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 difference between "==" and equals method in Java and finally when to use "==" and equals() to compare objects.
Difference between equals method and "==" operator in Java - Interview Question
Read more »
0 Response to "Difference between equals method and "==" operator in Java - Interview Question"
Posting Komentar