JAVA遍历Map所有元素

 

 

//JDK1.5   
Map map = new HashMap();     
for(Object obj : map.keySet()) {     
    Object key = obj;     
    Object value = map.get(obj);     
}   
  
//JDK1.4   
Map map =  new HashMap()   ;     
Iterator iter = map.entrySet().iterator();     
while(iter.hasNext()) {     
    Map.Entry entry = (Map.Entry)iter.next();     
    Object key = entry.getKey();     
    Object value = entry.getValue();     
}    
 

你可能感兴趣的:(java)