The object that the key maps to the value. A map cannot contain duplicate keys, and each key can be mapped to at most one value.
Some mapping implementations can explicitly guarantee their order, such as the TreeMap class, while others do not guarantee the order, such as the HashMap class.
Map elements, you can extract the key sequence, the value sequence alone.
Use Keyset () to extract the key sequence and generate a set for all keys in the map.
Use values () to extract the value sequence and generate a collection for all values in the map.
Why a build set, a Build collection? That's because key is always unique, and value allows repetition.
A collection that does not contain duplicate elements. More specifically, the set does not contain elements that satisfy e1.equals (E2) to E1 and E2, and contains a maximum of one null element.
Do not randomly access the contained elements
Only one-way traversal can be implemented with iterator
Set has no synchronization method
Random access to contained elements
Elements are ordered.
You can add and delete elements at any location
Element position unchanged no matter how many times it is accessed
Allow repeating elements
Implement one-way traversal with iterator, and also use Listiterator to implement bidirectional traversal
Advanced First Out
To avoid collection's add () and remove () methods as much as possible, use the offer () to add elements and use poll () to get and move out of the element. Their advantage is that the return value can be used to determine success or failure, and the Add () and remove () methods throw exceptions when they fail. If you want to use the front end without removing the element, use the element () or peek () method.
It is worth noting that the LinkedList class implements the queue interface, so we can use LinkedList as a queue.
Queue implementations generally do not allow the insertion of NULL elements, although some implementations, such as LinkedList, do not prohibit the insertion of NULL. Even in implementations that allow Nulls, NULL should not be inserted into the queue because Null is also used as a special return value for the poll method, indicating that the queue does not contain elements.
Last in, first out
The stack inherits from the vector (an array of objects that can grow) and is also synchronized
It extends the class vector by five operations, allowing the vector to be treated as a stack. It provides the usual push and pop operations, and the Peek method that takes the stack vertex, the empty method that tests if the stack is null, the search method that finds the item in the stack, and determines the distance to the top of the stack .
If you are involved in stacks, queues and other operations, you should consider using list;
For the need to quickly insert, delete elements, should use LinkedList;
If you need to quickly randomly access elements, you should use ArrayList.
If the program is in a single-threaded environment, or access is done only in one thread, it is more efficient to consider non-synchronous classes
Features and usage of MAP, Set, List, Queue, stack