This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the difference between == and .equals() method????  RSS feed

 
Vishal Hegde
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between == and .equals()method
 
Snehal Bachchhav
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..............

=-= Method checks wether two objects refer to same class
whereas equals method actually check values between two objects......................
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Snehal Bachchhav wrote:
=-= Method checks wether two objects refer to same class


== used to check two reference variables refers to same object

regards,
Anbarasu
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As everyone said, == is used to check if two references point to the same object. equals is used for meaningful comparison of objects. If you create a custom class (lets say employee class), then you can override the equals method to provide a meaningful comparison of objects (like check if empId is equal for two objects). The default implementation of equals method in Object class does a direct == comparison so is equivalent to using == operator (ignoring incompatible objects which cannot be compared) unless it is overridden...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!