创建 遍历Map

//新建Map
Map map= new HashMap();
for(int i = 0; i < apiList.size(); i ++){
     String name = apiList.get(i);
     map.put(name,0);
 }
//Map计数
if (map.containsKey(selectName)) {
    Integer num = (Integer) map.get(selectName);
    map.put(selectName, num + 1);
}
//遍历Map
//java Map 遍历速度最优解
//第一种: 
Map map = new HashMap(); 
Iterator iter = map.entrySet().iterator(); 
while (iter.hasNext()) { 
Map.Entry entry = (Map.Entry) iter.next(); 
Object key = entry.getKey(); 
Object val = entry.getValue(); 
} 
//效率高,以后一定要使用此种方式! 
//第二种: 
Map map = new HashMap(); 
Iterator iter = map.keySet().iterator(); 
while (iter.hasNext()) { 
Object key = iter.next(); 
Object val = map.get(key); 
} 
//效率低,以后尽量少使用! 
 

你可能感兴趣的:(map)