Design a HashMap Low Level Design
🧠Understanding HashMap in Java 1. What is a HashMap? Definition : A HashMap is a part of Java's Collections Framework that stores data in key-value pairs. Key Characteristics : Unique Keys : Each key in a HashMap is unique. Allows Nulls : Both keys and values can be null . Unordered : The order of entries is not guaranteed. 2. Internal Structure Bucket Array : Internally, a HashMap uses an array of buckets to store data. Node Class : Each bucket contains a linked list (or a balanced tree in Java 8 and above) of Node objects, where each node represents a key-value pair. static class Node< K , V > implements Map.Entry< K , V > { final int hash ; final K key ; V value ; Node< K , V > next ; } 3. How HashMap Stores Data Hashing : When a key-value pair is added: Calculate Hash : The hashCode() of the key is computed. Determine Bucket Index : The hash is used to determine the index in the bucket array. Handl...