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


Please Help Members By Posting Answers For Below Questions

What is singletonlist in java?

503


What is the escape character in java?

509


what do you understand by the term string with respect to java?

524


What’s the difference between unit, integration and functional testing?

612


What is an image buffer?

531






What is meant by inheritance and what are its advantages?

573


How does multithreading take place on a computer with a single cpu?

533


how to write a server program and sending the mails to the server using smtp protocol please help me

1546


How can we make a class singleton?

570


how to know the total memory occupied by the objects in the ArrayList(Array list may contain duplicate objects)

1899


What is the meaning of flag day?

534


What are the special characters?

531


Can I overload to string method

962


How to create an immutable class?

564


How do you read and print a string in java?

519