The usual way a hash card works is to have multiple bunkers (or codes) where you select a cell for a new key based on the hash code.
The problem is that several keys can fall into the same tray, since there are a limited number of boxes. A bean is a list. This way you can reach the bunker within O (1), but then you have to search linearly in the list. If this list becomes long, it degrades the performance of the hash table.
So, the current implementation of HashMap improves this problem by changing the structure of the box if the bit is too long. If the bunker already has more than 8 entries, and the number of boxes is more than 64, the bit is converted from the list to a red-black tree. A red-black tree is a balanced search tree. This means that the search will be O (log n), which is preferable to O (n).
So now, when you put the value in the basket, you have to check in which box it is. If it is a simple list, add to the list and, if it is a tree, add to the tree and balance it.
source share