This explanation is on how Java8 has implemented the HashMap, however, this doesn’t cover the better edge case collision handling situation which we will discuss later in this part…

1->Map<Integer, String> map = new HashMap<>();

2->map.put(1, “archie”);

3->map.put(2, “archiexzzz”);

4->map.get(1);

At code line no. 1, there is no size allocated to the hashmap. Java8 internally sets the DEFAULT_SIZE to 16. The sizes of HashMap are always in the form of 2x for better collision management.

By default the Default sized map is created:

For Each Key, a hashcode is generated and matched with the map length(note the hashcode should be within the range of the size)

If two entries find the same hashcode:

The last node of the linked list points to NULL and when a new node is added the last node’s pointer points to the next node and the next node’s pointer points to NULL again.

Entry Data Store for LinkedList node:

Key, Value, Pointer | null

Maximum Capacity:

Private static final int MAXIMUM_CAPACITY = 1 << 30;

The maximum capacity of the map is 1<<30 because: