2

As per the HashSet.java, the internal design of the HashSet uses HashMap

 public HashSet() {
        map = new HashMap<>();
    }

the java doc says

This class implements the Set interface, backed by a hash table (actually a HashMap instance).

Most of the books refer HashSet as "it is implemented by a hash table" by Java Generics

What is the reason for the strech of the HashTable ? Why not HashMap ?

1

2 Answers 2

4

A hash table is an abstract data structure that can be implemented in many different ways. In the Java standard library, HashMap is one such implementation, and HashTable is another. The wording in the documentation refers to hash tables in the generic.

Sign up to request clarification or add additional context in comments.

Comments

0

What they are trying to explain is that HashMap is a Java implementation of a general structure - the hash table. And that it implements the Set interface, which means that every entry is guaranteed to be unique

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.