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)