| 1. |
Can You Store A Duplicate Key In Hashmap? |
|
Answer» No, you cannot insert duplicate KEYS in HashMap, it doesn't allow duplicate keys. If you try to insert an existing key with new or same value then it will override the old value but size of HashMap will not change i.e. it will REMAIN same. This is ONE of the reason when you GET all keys from the HashMap by calling keySet() it returns a Set, not a Collection because Set doesn't allow duplicates. No, you cannot insert duplicate keys in HashMap, it doesn't allow duplicate keys. If you try to insert an existing key with new or same value then it will override the old value but size of HashMap will not change i.e. it will remain same. This is one of the reason when you get all keys from the HashMap by calling keySet() it returns a Set, not a Collection because Set doesn't allow duplicates. |
|