Set: Data Structure
Abstract data
Data Operation Method
Abstract data type
Data operation method + Data
Collection
Iterator: only the elements can be traversed in the forward order, and the elements can be deleted while traversing.
ListIterator
Forward Traversal
Post-order traversal: you must first move the iterator to the end of the set to traverse from behind
Insert element: add an element to the left of the iterator's current position
Delete element:
Traverse the elements on the left of the iterator in the forward order.
Post-order traversal deletes the right element of the iterator
Modify element:
An element must be skipped before modification.
Can be modified multiple times in a row
Obtain the current index (subscript)
List:
Focus on the index and sequence of Elements
Element duplication allowed
ArrayList dynamic array/Generic Array
Advantages:
Fast traversal and Random Access
Disadvantages:
Insertion and deletion are slow, occupying continuous memory space
Linked List
One-way, non-cyclic linked list
One-way cyclic linked list
Bidirectional non-circular linked list
Bidirectional cyclic linked list
Headless linked list
Advantages:
Insert, fast Deletion
Disadvantages:
Random Access is not provided. The subscript used indicates the number of nodes passing through the node from the first node.
Stack: First releases FirstInLastOut
Queue: first-in-first-out FirstInFirstOut
Set: Hash --> Hash
Ignore element index
Repeated elements are not allowed.
Calculate element Subscript: hashCode % bucket (array length)
HashSet
Unordered, unclassified set
The hashCode and equals methods must be rewritten for custom objects.
Provides a basis for HashSet to determine whether objects are the same
LinkedHashSet
Sort the Hash version strictly by the insertion order
TreeSet
Hash sort version, sorted by element size
Sorted from small to small by default
Equals: compare whether the content of two objects is the same
CompareTo: Compare the size of two objects
It must be rewritten. This method must be rewritten when a custom object is created.
HashCode and equals
When all attributes of two objects are the same
The two objects are the same object.
Map
Key-value ing relationship
Key uniqueness
HashMap
Unordered
Without an iterator, you can only traverse the view.
Entry view key-value
Key View
Value View
LinkedHashMap
Sort by element order
TreeMap
Sort by key size
Comparator: Comparator
Tells TreeMap how to sort elements in a set
Custom sorting rules