18th Day of Java Learning (map collection)

Source: Internet
Author: User

A map collection is an object that maps keys to values. A map cannot contain duplicate keys, and each key can be mapped to at most one value. A key-value pair is stored in the form of an element, the key is unique, the value can be repeated, a bit similar to the primary key in the database plus data. The main functions are:

A: Add Features

Put method
B: Delete Feature

Remove method

C: Judging function

Boolean ContainsKey (Object key)//Determine if a key is included

Boolean containsvalue (Object Value)

Boolean IsEmpty ()
D: Get Features

Get method//Example Description


E: Length function

Map<string,string> HM = new hashmap<string,string> ();

Hm.put ("it002", "Hello");
Hm.put ("it003", "World");
Hm.put ("it001", "Java");

Mode 1 Key Find value
set<string> set = Hm.keyset ();
for (String Key:set) {
String value = Hm.get (key);
System.out.println (key+ "---" +value);
}

Method 2 Key value to object find key and value
Set<map.entry<string,string>> Set2 = Hm.entryset ();
for (map.entry<string,string> Me:set2) {
String key = Me.getkey ();
String value = Me.getvalue ();
System.out.println (key+ "---" +value);

18th Day of Java Learning (map collection)

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.