Pages

Tuesday, 25 December 2012

What is the difference between .equals and ==

== checks for identity. That is whether the two objects are the same object and point to the same address in memory.

.equals() by default does the same thing, but can be overridden to perform different equality comparisons. (i.e. strings are considered equal if they have the same characters in the same order)

instanceof checks if an instance is an instance of a given class e.g.if ("hello" instanceof String)

No comments:

Post a Comment