1. What is difference between == operator and .equals() method?
== Opertor .equals() method
=========================================== ==============================================
-> It is an operator, applicable for both premitives -> It is a method, applicable only for Object types but
and Object types. not premitives.
--------------------------------------------------- --------------------------------------------------------------
-> In general == operator meant -> in general .equals method is used for content comparision.
for reference/address comparision.
--------------------------------------------------- ---------------------------------------------------------------------
-> It is not possible to override == operator for -> It is possible to override equals(-) method for content
content comparision. comparision.
------------------------------------------------- -----------------------------------------------------------------------
Note:**.equals method present in object class also meant for reference comparision only based on our requirement we can override fro content comparision.
** In string class all wrapper class and all collection classes .equals() is overridden for content comparision.
== Opertor .equals() method
=========================================== ==============================================
-> It is an operator, applicable for both premitives -> It is a method, applicable only for Object types but
and Object types. not premitives.
--------------------------------------------------- --------------------------------------------------------------
-> In general == operator meant -> in general .equals method is used for content comparision.
for reference/address comparision.
--------------------------------------------------- ---------------------------------------------------------------------
-> It is not possible to override == operator for -> It is possible to override equals(-) method for content
content comparision. comparision.
------------------------------------------------- -----------------------------------------------------------------------
Note:**.equals method present in object class also meant for reference comparision only based on our requirement we can override fro content comparision.
** In string class all wrapper class and all collection classes .equals() is overridden for content comparision.
Comments
Post a Comment