Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

Apart from the fact that HashSet does not allow duplicate values, what is the difference between HashMap and HashSet?

I mean implementation wise? It's a little bit vague because both use hash tables to store values.

1 Answer

0 votes
by (46k points)

They are entirely different constructs. A HashMap is an implementation of Map. A Map maps keys to values. The key look up occurs using the hash.

On the other hand, a HashSet is an implementation of Set. A Set is designed to match the mathematical model of a set. A HashSet does use a HashMap to back its implementation, as you noted. However, it implements an entirely different interface.

Related questions

0 votes
1 answer
asked Nov 12, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 7, 2021 in Java by dante07 (13.1k points)

Browse Categories

...