遍历MAP类型的里的内容

Iterator it = map.entrySet().iterator();
while(it.hasNext()) {
  Map.Entry entry = (Map.Entry)it.next();
  Object key = entry.getKey();
  Object value = entry.getValue();
}
Iterator   itor   =   mm.values().iterator(); 
while(itor.hasNext()){
itor.next();
}
 
for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry) iter.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            // ...
}
 
 
JDK   1.5   以上,并且还使用了泛型   Map   的话,可以使用   foreach   来遍历。 

Java code
        
        
        
        
import java.util.LinkedHashMap; import java.util.Map; public class Test { public static void main(String args[]) { Map < String, String > map = new LinkedHashMap < String, String > (); map.put( " 1 " , " a " ); map.put( " 2 " , " b " ); for (Map.Entry < String, String > entry : map.entrySet()) { System.out.println(entry.getKey() + " --> " + entry.getValue()); } } }

你可能感兴趣的:(map,职场,休闲)