Java-preliminary Understanding-Common Object API (collection framework-map Collection features common methods)

Source: Internet
Author: User
Tags dashed line

One.

Now take a look at the composition of the collection, the left Two-thirds part is all finished, and there is a set map on the right.

Map and collection are side-by-side and are the top-level interfaces in the collection, why interfaces? Because it's a dashed line. Map collection is very important, now to learn, the use of very high frequency.

Learn the map collection and learn its basic features first. If the map collection is the same as collection, then it is not fun, so what is the difference between map and collection?

Collection adds one at a time, and the map adds a pair at a time.

Do you have any other features? We found that here the map is followed by K and V, previously seen in E and t,e is Element,t is temp (? )。

K is the key, V is the value, in fact, the map set is stored in the key value pairs, at the same time, the map set must ensure the uniqueness of the key. When we get here, we're done with the map collection.

Map is a container that should provide some common methods that are said to add, delete ..... Let's see, what are the methods of it?

In many ways of learning about collections, classifying them is easier to learn.

If the map collection has a method to add, does it receive several parameters? Two parameters are received and V is returned.

In the return interpretation, K1 and V1 are key pairs that are stored in. If you save K1 and V2 again, the key is the same, and the new value replaces the old value, and the old value is returned. When storing K1 and V1, what is returned? There is no previous value, which is null. Added to the end, especially simple.

Here is the Purge method, either clear or remove. The Remove method has only one parameter that removes the pair of elements according to the key, but returns the value corresponding to the key. Usually remove the length of the match.

Judgment: include Key not? Does it contain a value? Is it empty, is there a key value right?

Here's how to get it, (what does the key and value mean?) )

Value get (key), which is obtained by key. What if I don't have a key?

In other words, if there is no key, return is null. This method also has additional operations, in addition to fetching, can also determine whether to return NULL, whether the specified key is included. Note: The K1 and V1 stored in, through the K1 to return V1, through the K2, return what? This is where K1 and V1 are stored, K2 is not, and Null is returned. It is possible to judge by Null that the set does not contain the corresponding relationship of K2.

There is one more way to do this is size.

There are other ways to put it in the back of the story.

Java-preliminary Understanding-Common Object API (collection framework-map Collection features common methods)

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.