The underlying implementation principle of the hashmap collection of the map collection --- preliminary exploration

The underlying implementation of hashmap is simply (hash table) array + linked list + red-black tree,
but HashMap uses linked list method to avoid hash conflicts (same hash value). When the length of the linked list is greater than 8 (default), the linked list is converted It is a red-black tree. When it is less than 6 (default), it will switch back to the linked list. The performance balance has been reached.
Insert picture description here
What is a red-black tree? A
red-black tree is a kind of balanced binary tree. It has the following characteristics: the
node has only two colors of red and black.
Two red nodes cannot be connected together
. The child nodes of the red node must be black.
Red-black trees always achieve self-balance through rotation and discoloration
Insert picture description here

Guess you like

Origin blog.csdn.net/Wangdiankun/article/details/106127845