Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java  RSS feed

 
kavita.ingale ingale
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is diff between hashcode and equal method of Object class?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this article on Equals & Hashcode

Also, go through the javadoc of the equals and hashcode methods in the Object class.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

This "Other Java Products and Servers" forum is for questions about... well, Java add-on products and servers, not the Java language itself. We have a "Java in General (Beginner)" forum where this question fits right in. I will move it there for you.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,


Two things need to remember:

1)If two objects hash code is equal then it is not necessary that two objects are equal.

2) If two objects are equal, then their hash code must be equal.

So lets take it in this way:

Assume you have a group of objects you want differentiate on one property:

1) All objects with same property are in same line but they may have different properties.

The unique identification is Hashcode.

More inputs are welcome.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!