In the list, set, and map implementations provided by JDK, the set type depends on the MAP storage method. The map object is stored in a tree structure and a hash (hash) structure; the list object depends on the array and linked list structure.
Type implementation class Storage Structure
List arraylist Array
Linked List
Set hashset Hash (hash) Table
Treeset Tree Structure
Map hashmap Hash (hash) Table
Treemap Tree Structure
The data stored in the list type must not be unique, that is, the data in the list can have multiple identical data, that is, list. get (I ). equals (list. get (j) = true (I! = J ).
The data stored in the set type must be unique, that is, there cannot be multiple identical data in the list. If the same data is stored in the set type, the next data overwrites the previous data.
Map uses the storage method of the K-V, In the map object, the key is not allowed to repeat, if repeated, the last key overwrites the previous key, but the value can be repeated.
You can select Data Objects Based on data storage requirements during your work. If the stored data may have duplicate data, you cannot select the set storage method instead of map or list.
Of course, list, set, and map have advantages and disadvantages when storing data.
Advantages and Disadvantages of implementing a class storage structure
The arraylist array can be used to quickly query and insert a small amount of data. The performance is low when a large amount of data is inserted and removed.
The shortlist linked list can be quickly inserted, and the performance of the removed query data is inferior to that of the arraylist
Hashset hash is ideal for both the neutral performance in the data storage process. There is a data conflict in the hash. In this case
although rare, it is inevitable to store a large amount of data.
if no capacity is set during initialization, the default value is
it is a waste of space to the power of 2, if it is set
The user needs to estimate the data size.
Treeset tree-like insert, with good removal efficiency, less efficient data query than hashset.
Hashmap is the same as hashset.
Treemap and treeset
Post-completion remarks: During the idle period of the project, I read the commonly used collections types, and I feel pretty good.Source codeIt is indeed an improvementCodeThe best way to quality ". Now I want to read the sorting and iterator interfaces in the collections framework.