Collection
|--list Orderly, repeatable
|--arraylist
The underlying data structure is an array, query fast, and delete slowly.
Thread insecure, high efficiency
|--vector
The underlying data structure is an array, query fast, and delete slowly.
Thread-safe, low-efficiency
|--linkedlist
The underlying data structure is linked list, query slow, delete quickly.
Thread insecure, high efficiency
|--set disorder, the only
|--hashset
The underlying data structure is a hash table.
How to guarantee the uniqueness of the element?
Dependent on two methods: Hashcode () and Equals ()
These two methods can be generated automatically in development
|--linkedhashset
The underlying data structures are linked lists and hash tables
The chain list ensures that the elements are orderly
Guaranteed element unique by hash table
|--treeset
The underlying data structure is a red-black tree.
How do you ensure that elements are sorted?
Natural sort
Comparator sort
How to guarantee the uniqueness of the element?
Depends on whether the return value of the comparison is
How to choose
Is it the only one?
Yes: Set
Sort of?
Yes: TreeSet
No: HashSet
If you know it is set, but do not know which set it is, use HashSet.
No: List
Are you safe?
Yes: Vector
No: ArrayList or LinkedList
Query MORE: ArrayList
More additions and deletions: LinkedList
If you know it is list, but do not know which list, use ArrayList.
If you know it is collection collection, but do not know who to use, use ArrayList.
If you know how to use a collection, use ArrayList.
Differences and choices for Java collections