Java-preliminary Understanding-Common Object API (collection framework-common method Demo)

Source: Internet
Author: User

One.

The method is explained, and a demonstration is done.

Create an object in the main function, here is the map reference, (why do you do it by method?). )。 Map has generics, what type of map do you want to manipulate?

Writing a school number and name is a mapping relationship. To figure out, what is the difference between a map set and a collection, and when does it work? This is the most important, the method is finished to know.

The number is an integer type, which means that the int type is hung and a packet is directed.

In method methods, adding elements to the Map collection is the use of the Put method. The Put method will have a return value. Create the Map object in the main function, and then call the method methods.

What type of new map object do you want to use here? (Is it because the map is an interface, to find the following sub-class to operate?) )

Looking for a suitable subclass to use as the type of the new map object, the subclasses often used are several, such as HashMap,

After using HashMap, the result is correct.

Collectin is a single-column collection, and map is a double-row collection. Print the collection and get the keys and values. Connect with an equal sign, indicating that it has a relationship.

For the result of the above operation, there are a few comments, the same key, the value will be overwritten.

Next, store a few more. The output display is unordered. Do not mean that 2,7,8 is orderly, hashmap is also a hash table, the integer method and the hash table is the same way.

the next demonstration is the Delete method, in the Map collection, the corresponding key value is deleted, the value returned.

Here is the judgment, and the result returns ture.

Finally, the method is obtained and the result is Xiaoqiang. Preserves the corresponding key-value pairs in the collection. If you enter a key that does not exist, the return is null.

Java-preliminary Understanding-Common Object API (collection framework-common method Demo)

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.