Common method of map

     Chat yesterday and colleagues, he said to traverse all values ​​map out; suddenly skull stuck; 

So he consolidated the case; there is something wrong, correct comments are welcome;

Map of common methods

map.put ();   was added ;

as map.get (key);   obtaining a corresponding key of the values;

map.values ();   obtaining map all the values values ;

map.keySet (); get all the key values

map.size (); the size of the length of the element

EnumMap.entrySet (); acquiring map of all elements , k1 = v2, k2 = v2 , ....... form output ;

map.remove (key); removing the respective key element ;

map.putAll (map1); the element into the map map1; 

    During the preparation process, a phenomenon found: if (kv) of map two types of inconsistencies, such as map --- (1, "a"); map1 --- ( "1", "b");   

     map.putAll performed (map1); ---- map output is:

     [1=a, 1=b]

JDK8 add new features lambda expression to traverse Map method --Map.forEach ();

Map.forEach((k,v)->{

System.out.println(k+":"+v);

});

Case are as follows :

 

 

Guess you like

Origin www.cnblogs.com/Object11/p/11653683.html