Java HashSet vs HashMap

后端 未结 7 1795
长发绾君心
长发绾君心 2020-12-12 16:13

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

7条回答
  •  执念已碎
    2020-12-12 16:45

    A key in a Map can only map to a single value. So the second time you put in to the map with the same key, it overwrites the first entry.

提交回复
热议问题