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
Objects or references which of them gets garbage collected?
What is set and get methods in java?
Can we catch more than one exception in a single catch block?
How do you identify independent and dependent variables?
Which class should you use to obtain design information about an object in java programming?
What do you mean by hashing?
What do you understand by the term wrapper classes?
Can private class be inherited in java?
What is the difference between sleep and wait in java?
What is the functionability stubs and skeletons?
What is the exception hierarchy in java?
Explain different states of a thread in java?
What is difference between protected and private?
What are the advantages of autoboxing?
What is the relationship between clipping and repainting under awt?