1. Data Structure need to store the Store the key-value pair.
Make an Entry class to store the HashMap Entries.
Variable: key, value and next
next (Entry) variable is used to avoid the collision of hashmap using chaining (linked list).
2. put() method to put new entries in hashmap.
Identify the bucket using hash (hashcode%SIZE)
a. If no element exists in that bucket: put it as new Entry.
b. If element already exists:
If element is duplicate, replace old one, otherwise find the last element in the chain and add new entry to next pointer of last element.
3. get() method : return the element in the hashmap
Identify the element bucket by calculate the hash (hashcode%SIZE) of the key, and return the element using equals method.
4. Define size in power on 2
Rehashing is good when the size is exponential of 2.
Set initial size = 2^4 = 16.
To expanding HashMap, make size to its double using power, i.e. 2^5= 32.
To reducing HashMap, make size to its half using power, i.e. 2^3= 8.