List interface, Set interface, Map interface, list interface setmap
1. The List and Set interfaces inherit from the Collection interface, while Map is not the inherited Collection interface.
Map does not inherit the Collection interface. Map provides a key ing between key and value. A Map cannot contain the same key, and each key can only Map one value. The Map interface provides three sets of views,
The Map content can be treated as a set of keys, a set of values, or a set of key-value ing;
2. List Interface
Elements are placed in order and can be repeated.
The List interface has three implementation classes: rule List, ArrayList, and Vector.
Hierarchical list: the underlying layer is implemented based on the linked list. The linked list memory is scattered. Each element stores its own memory address and also stores the address of the next element. Fast addition and deletion of linked lists, slow Query
The difference between ArrayList and Vector: ArrayList is non-thread-safe and efficient. Vector is thread-safe, and low-efficiency elements are put in order, and the elements can be repeated.
List is an ordered Collection. You can access the data in the Collection through indexes. List has 10 more methods than Collection, mainly related to indexes.
1). All methods returned by indexes may throw an IndexOutOfBoundsException exception.
2). subList (int fromIndex, int toIndex) returns fromIndex, excluding the toIndex view. The size () of the list = toIndex-fromIndex.
All lists can only contain tables composed of a single object of different types, rather than Key-Value pairs. Example: [tom, 1, c];
- All lists can have the same elements, such as [tom, koo, too, koo] in the Vector;
- All lists can have null elements, such as [tom, null, 1];
- Array-based List (Vector, ArrayList) is suitable for queries, while sorted List (linked List) is suitable for adding and deleting operations;
3. Set Interface
Elements are not placed in order and cannot be repeated. (Note: although elements are not placed in order, the position of an element in the set is determined by the HashCode of the element, and its position is actually fixed)
The Set interface has two implementation classes: HashSet (implemented by HashMap at the underlying layer) and LinkedHashSet
The SortedSet interface has an implementation class: TreeSet (the underlying layer is implemented by the balanced binary tree)
The Query interface has an implementation class: LinkList
Set has the same interface as Collection, so there is no additional function, unlike the previous two different lists. Set is actually a Collection, but the behavior is different. (This is a typical application of inheritance and Polymorphism: different behavior .) Set does not store repeated elements (it is more responsible for determining how to determine if the elements are the same)
Set: Each element stored in the Set must be unique because the Set does not store duplicate elements. The equals () method must be defined for the element added to the Set to ensure the uniqueness of the object. Set has the same interface as Collection. The Set interface does not guarantee the order of maintenance elements.
HashSet: A Set designed for quick search. The object stored in the HashSet must define hashCode ().
TreeSet: The Set that stores the order. The bottom layer is the tree structure. It can be used to extract ordered sequences from the Set.
LinkedHashSet: query speed with a HashSet, and internal use of the linked list to maintain the order of elements (insert order ). When you use the iterator to traverse the Set, the result is inserted in the order of elements.
4. Map Interface
The Map interface has three implementation classes: HashMap, HashTable, and LinkeHashMap.
HashMap is non-thread safe, efficient, and supports null;
HashTable thread security, low efficiency, does not support null
SortedMap has an implementation class: TreeMap