Map usage in java (HaspMap usage), maphaspmap
public interface Map<K,V>
Objects that map keys to values. A ing cannot contain duplicate keys. Each key can only be mapped to one value at most.
1 import java. util. hashMap; 2 import java. util. map; 3 4 5 public class Test1 {6 7 public static void main (String [] args) {8 Map map = new HashMap (); // declare a Map 9 map. put ("s", "Haha"); // put the value in map: 10 String str = map stored in the form of key-value. get ("s "). toString (); // map to obtain the value11 System whose key is "s. out. println (str); 12} 13}
Output: Haha
Map key-value pairs, whose values are generally stored as objects.
Put (object key, object value), a common method in hashmap, associates the specified value with the specified key in the ing.
Get (object key); // find the corresponding value based on the key value.
Check whether the key exists: containsKey (object key)
Check whether the value exists: containsValue (object value)
The Map feature is Key-Value matching.
1 import java. util. hashMap; 2 import java. util. map; 3 4 5 6 public class Test1 {7 8 public static void main (String [] args) {9 Map map = new HashMap (); 10 String key1 = "java1 "; 11 String key2 = "java2"; 12 map. put (key1, "java1 value"); 13 map. put (key2, "java2 value"); 14 System. out. println (map. get (key1); 15 System. out. println (map. get (key2); 16} 17}
Output:
Java1 Value
Java2 Value