A hash set stores only keys, while a hash map stores keys paired with values. Both hash each key to place and find entries fast. The difference is what each slot holds.
A set answers one question, whether a key is present. You add keys and later ask whether a key is in the collection. A map answers a richer question, which value goes with a given key.
seen.add("alice"); // set: membership only
ages.set("alice", 30); // map: key -> value
Use a set when you only care about presence or uniqueness, like tracking which IDs you have already processed. Use a map when each key needs an attached value. Internally, a set is often a map whose values are placeholders.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓