1. Overview of the Map collection:
1 Public Interface Map<k,v>
As a student, is based on the number to distinguish between different students, then assume that I now know the student's number, I have to according to the number to obtain the student's name, how to do it?
If we use the previously explained set, we can only use the number and student name as a member of an object, and then store the entire object, in the future, when the traversal, judge, get the corresponding name.
But, if I can take the student's name out, do I still need to find it by number?
For our current needs: just know the student number and want to know the names of the students, Java provides a new set of Map.
By looking at the API, we know that one of the biggest features of the map collection is that it can store elements of key-value pairs . This is the time to store the requirements above and we can do this.
School Number 1 Name 1
School Number 2 Name 2
School Number 3 Name 3
School Number 2 (NO) name 4
School Number 4 Name 4
2. Features of the Map collection:
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.
3. What are the differences between the map collection and the collection collection?
The map collection storage elements are paired, and the keys of the map collection are unique and the values are repeatable. This can be understood as: couples
The collection collection storage element appears separately, and the collection son set is unique and the list is repeatable. This can be understood as: Bachelor (11.11)
Attention:
The data structure of the map collection is only valid for keys, regardless of value
Hashmap,treemap, etc. will speak.
The data structure of the collection collection is valid for the element
Overview and features of the map collection of the collection framework note 50:map collection of Java Fundamentals enhancement