| 1. |
How Does Hashmap Handle Collisions In Java? |
|
Answer» The java.util.HashMap uses chaining to handle COLLISIONS, which means new entries, an OBJECT which contains both key and values, are stored in a linked list along with EXISTING value and then that linked list is stored in the bucket location. In the worst case, where all key has the same hashcode, your hash table will be turned into a linked list and searching a value will take O(n) time as opposed to O(1) time. The java.util.HashMap uses chaining to handle collisions, which means new entries, an object which contains both key and values, are stored in a linked list along with existing value and then that linked list is stored in the bucket location. In the worst case, where all key has the same hashcode, your hash table will be turned into a linked list and searching a value will take O(n) time as opposed to O(1) time. |
|