Overview and features of the map collection of the collection framework note 50:map collection of Java Fundamentals enhancement

Source: Internet
Author: User
Tags new set

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.