- Set interface belongs to an abstract class
- Set the following two implementation class, HashSet and TreeSet
A, Set Interface
1, Set Overview
- It does not contain a repeat element Collection
2, Set case
- Storage string and ergodic
- Store custom objects and traverse
Two, HashSet implementation class
1, HashSet Class Overview
- We do not guarantee the iteration order of the set
- In particular, it does not guarantee that the order lasts forever
Uniqueness 2, HashSet how packaging elements
-
The underlying data structure is a hash table (array element is a linked list)
-
Hash table depends on the stored hash value
-
Add the underlying functionality relies on two methods:
int hashCode()
boolean equals(Object obj)
Three, LinkedHashSet implementation class
1 Overview
- The only element of order
- A list of elements to ensure the orderly
- By a hash table to ensure that the only element
Four, TreeSet implementation class
1 Overview
- Using elemental natural order sort elements
- Or sorted according to a Comparator provided when creating Set
- Configuration depends on the specific method used
2, TreeSet is how to ensure the sort of elements and uniqueness
- The underlying data structure is a red-black tree (red-black tree is a self-balancing binary tree)