If you have millions of students stored in the program and often need to use the number to search for a student, the data structure that is needed to be effective isMap. Mapis a key (Key) stores the container for the element, the key (Key) Much like subscript, inListthe middle subscript is an integer. In theMapMiddle Key (Key) can make an object of any type. Mapcannot have duplicate keys (Key), each key (Key) has a corresponding value (value). A key (Key) and its corresponding values constituteMapan element in the collection.
the elements in Map are two objects, an object as a key, and an object as a value. The key cannot be repeated, but the value can be repeated.
look at the top-level commonality method to find the subclass-specific object .
Interface map<k,v>
K-The type of key maintained by this mapping
V- type of the mapped value
Concept
The object that maps the key to a value. A map cannot contain duplicate keys, and each key can be mapped to at most one value.
Characteristics
Key and Value are 1-to -1 relationships, such as: House number: Home husband : wife
Two-column collection
---| The map interface maps the key to the object of the value. A map cannot contain duplicate keys, and each key can be mapped to at most one value.
---| HashMap is implemented with a hash table, so unordered
---| TreeMap can sort the health
---| Hashtable:
The underlying is the hash table data structure, where threads are synchronized and cannot be stored as null keys,null values.
less efficient and is HashMap substitution.
---| HASHMAP:
The underlying is a hash table data structure that the thread is not synchronized and can be stored in a null key,null value.
to guarantee the uniqueness of the key, you need to override the Hashcode method, and the Equals method.
---| Linkedhashmap:
the subclass is based on a hash table and is incorporated into the list. You can increase the efficiency by adding or deleting the Map collection.
---| TREEMAP:
the bottom layer is a two-fork tree data structure. You can sort the keys in the map collection. You need to use comparable or Comparator for comparison sorting. return 0, to determine the uniqueness of the key.
Summarize:
Map and collection are juxtaposed in the set frame,
The 1.Map stores a key-value pair,
2..MAP storage elements using the Put method, collection using the Add method
The 3..Map collection does not take the method of extracting the element directly, but rather turns it into a set set, where the element is fetched by iteration
4..Map set Middle key to ensure uniqueness
5.. that is, collection is a single-column collection, and Map is a double-row collection.
Map saves one pair of elements at a time, Collection one at a time. Map keys cannot be duplicated and are guaranteed to be unique.
The map is stored in a pair of elements at a time, in the form of a key-value pair. The key has a mapping relationship with the value. Be sure to keep the key unique.
The Java Map Collection