Map is a container that stores elements according to keys . Keys are like subscripts. In List, subscripts are integers. In Map, keys can be objects of any type. There cannot be duplicate keys in the Map, and each key has a corresponding value .
A key and its corresponding value constitute an element in the map collection. The elements in the Map are two objects, one object as the key and one object as the value. Keys cannot be repeated, but values can.
1) The Map set is a two-column set. One element contains two values, one is the key and the other is the value.
2) The keys and values of the elements in the Map collection can be the same or different.
3) For elements in the Map collection, the key is not allowed to be repeated, but the value can be repeated.
4) The elements in the Map collection have one-to-one correspondence between key and value.
The bottom layer of the HashMap collection is a hash table, and the query speed is extremely fast. Before JDK 1.8, it was array + one-way linked list, and after JDK 1.8, it was array + one-way linked list/red-black tree (the length of the linked list exceeds 8). The HashMap set is an unordered set, and the order of stored elements and retrieved elements may be inconsistent.
The bottom layer of the LinkedHashMap collection is a hash table + linked list. The collection is an ordered collection, and the order of storing elements and removing elements is consistent.
Add the specified key and specified value to the Map collection, and return the value V. When storing key-value pairs, the key is not repeated, and the return value V is null; if the key is repeated, a new value will be used to replace the repeated value in the Map. , returns the replaced value.
Delete the key-value pair element corresponding to the specified key in the Map collection and return the value of the deleted element. The return value is V. If the key exists, V returns the deleted value; if the key does not exist, V returns null.
According to the specified key, obtain the corresponding value in the Map collection and return the value V. If the key exists, V returns the corresponding value; if the key does not exist, V returns null.