Does adding a duplicate value to a HashSet/HashMap replace the previous value

前端 未结 8 1593
迷失自我
迷失自我 2020-12-02 07:14

Please consider the below piece of code:

HashSet hs = new HashSet();
hs.add(\"hi\"); -- (1)
hs.add(\"hi\"); -- (2)

hs.size() w

8条回答
  •  误落风尘
    2020-12-02 07:55

    In the case of HashMap, it replaces the old value with the new one.

    In the case of HashSet, the item isn't inserted.

提交回复
热议问题