In an HashMap the key is an object, that contains hashCode() and equals(Object) methods.
When you insert a new entry on the Map, it checks whether the hashCode is already known. Then, it will iterate through all objects with this hashcode, and test their equality with .equals(). If an equal object is found, the new value replace the old one. If not, it will create a new entry in the map.
Usually, talking about maps, you use collision when two objects have the same hashCode but they are different. They are internally stored in a list.
solve
Problem:
There are chances that the hashFunction returns same index for 2 different keys. This is what we call a collision.
Solution:
Separate Chaining: Have an array of lists. If there is more than one key hashed to the same index, append to the list at that index in the array. A decent hash function guarantees that the keys are evenly distributed across the indices. This is what Java uses.
2-Choice: It is similar to Separate Chaining, just that there are 2 hash functions instead of 1. Get the indices from both the hash function. Compare the sizes of the list at these indices and append the new key to the smaller list. This can be extended to k-Choice.
Cuckoo hashing: You have 2 hash functions. Let the first hash function return x. If vacant, put the key K there, if not, try the second hash function and let's say it returns y, put the key there if vacant. If not, kick out the key L at y and store K there. Run both the hash functions on L and try the other index ignoring the index at which it previously it used. Repeat the process. If you cannot find a spot for it after 15 retries, put it in the overflow table.