Collision : 

The collision occurs when 2 different objects have the same hash code.

The Java HashMap already handles collisions for you in this way. All you need to do is ensure you are overriding and implementing the key’s hashCode() and equals() method.

Each hash code will map to a specific “bucket”. Each bucket contains a linked list for the case of collisions.

The only way to avoid (or rather minimize) collisions is to create a hash function that creates the best possible distribution of values throughout the HashMap. Depending on the density of your HashMap and the quality of your hash code, collisions are almost inevitable, hence the need to override the two methods.

In short we can minimize/avoid collisions by overriding hashcode() and equals() methods