From charlesreid1

Sets can utilize many of the same OOP features during implementation that Maps do (see Maps/OOP).

However, one important feature is that sets can be implemented using nothing more than a hash table or hash map, where the value itself is its own key. This enables the definition of a Set class, whose interface may be entirely different from a map or a hash table, but which nevertheless utilizes these data structures under the hood.

The Set class should not just blindly use the HashMap, however, as the HashMap allocates space for both keys and values, and all we need to implement a set are the values.

As in mathematics, the Set type can be thought of as an elemental building block of more complex objects. For example, @phishman3579 on github implemented several data structures in Java (Link:, but one he did not implement was the Set type. Instead, his library relies on the Java API's HashSet, TreeSet, and AbstractSet classes.