whats the difference between == and .equal ?
Answer Posted / qim2010
The == returns true, if the variable reference points to the
same object in memory. This is a “shallow comparison”.
The equals() - returns the results of running the equals()
method of a user supplied class, which compares the
attribute values. The equals() method provides “deep
comparison” by checking if two objects are logically equal
as opposed to the shallow comparison provided by the
operator ==. If equals() method does not exist in a user
supplied class then the inherited Object class's equals()
method is run which evaluates if the references point to the
same object in memory. The object.equals() works
just like the "==" operator (i.e shallow comparison).
Overriding the Object class may seem simple but there are
many ways to get it wrong, and consequence can be
unpredictable behavior.
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
Is math class static in java?
What is the purpose of object oriented programming?
What is assembly used for?
Is string is a data type?
What is difference between this and super keyword?
Can I learn java without any programming experience?
What are the 3 types of loops in java?
What are the 8 data types in java?
Why deletion in linkedlist is fast than arraylist?
How to add menushortcut to menu item?
What is try-with-resources in java?
How to retrieve data from database in java using arraylist?
What is tochararray in java?
What is an argument java?
Why string is not thread safe?