• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 537
  • Last Modified:

what is the purpose of hash code and equals method in hashset

what is the purpose of hash code and equals method  in hashset
0
Manikandan Thiagarajan
Asked:
Manikandan Thiagarajan
1 Solution
 
zzynxSoftware engineerCommented:
0
 
Sharon SethCommented:
To that matter , hashCode() and equals() method in any Object , is a way of  specifying what it means for two objects to be equal .
Say you have two integers 2 and 3 . You simply say they are not equal . But when it comes to Objects , say an Employee object , you have to very clearly put down when you can say two employee objects are equal (or not equal) . hashCode() and equals() are the methods that put down this logic
0
 
krakatoaCommented:
hashCode() is a (hopefully) non-colliding 32 bit integer affording the object it refers to a unique handle. equals() is the way that handle gets compared to another object's hashCode, to determine if it is the same object or not. The same for HashSet, where it's used to determine if the object is itself a set - of the same size and with the same membership.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now