Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vishal Hegde
Ranch Hand
Posts: 1077
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: 9528
32
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