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
Difference between character constant and string constant in java ?
How is a structure different from array ?
What is the function of log?
What is the use of default method in interface in java? Explain
What is the difference between menuitem and checkboxmenu item?
What is oops in java?
How many bytes are there?
What will happen if static modifier is removed from the signature of the main method?
How would you use Bubble Sort to sort the number of elements?
what do you understand by synchronization? : Java thread
What are the different types of garbage collectors in java?
Are maps ordered java?
What is a functional interface?
Can we have a method name same as class name in java?
What are the loops in java?