Does anyone use hashCode() anywhere?
Can anyone give me an example of the exact use of hashcode and in which cases we need to implement it?
Any specific area where HashCode is being used?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
hashCodemethod is used internally by for instanceHashSetorHashMapetc.It is used to for instance allow an algorithm to quickly discover if two objects are not equal. (Without comparing them using
equals.)You should implement it whenever you override
equals(which you need to do whenever you need to define two different objects to be equal).Further reading