Apart from the fact that HashSet does not allow duplicate values, what is the difference between HashMap and HashSet in their implementation?
It’s a little bit vague because both use hash tables to store values.
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.
They are entirely different constructs. A
HashMapis an implementation ofMap. A Map maps keys to values. The key look up occurs using the hash.On the other hand, a
HashSetis an implementation ofSet. A Set is designed to match the mathematical model of a set. AHashSetdoes use aHashMapto back its implementation, as you noted. However, it implements an entirely different interface.When you are looking for what will be the best
Collectionfor your purposes, this Tutorial is a good starting place. If you truly want to know what’s going on, there’s a book for that, too.