Data structure of hash table in java Set collection

In the Java Set collection, the hash table of hashSet before jdk1.8 is array + linked list, after 1.8, the value array + linked list/red-black tree, the threshold for changing from a linked list to a red-black tree is 8, when it is greater than or equal to 8. Become a red-black tree, its purpose is to query fast

1. The basic structure of the
hash table The hash table consists of an array and a linked list/red-black tree. In the array, the hashCode value of the stored data is stored. The same value is placed in the same array, and then the equals value is compared. If the same The difference is not stored, and the difference is increased downward through the linked list. This is the non-repeatability. When querying, the linked list will be output one by one, and the same data in a linked list will be output together, so there will be a disorder .
1.1 The structure of array + linked list is shown in the figure below
Insert picture description here
1.2 The structure of array + red and black tree is shown in the figure below
Insert picture description here

Guess you like

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