I understand that HashSet is based on HashMap implementation but is used when you need unique set of elements. So why in the next code when putting
I think the major difference is, HashSet is stable in the sense, it doesn't replace duplicate value (if found after inserting first unique key, just discard all future duplicates), and HashMap will make the effort to replace old with new duplicate value. So there must be overhead in HashMap of inserting new duplicate item.