map遍历

1.用for循环
for(Map.Entry entry:map.entrySet()){
          System.out.println(entry.getKey()+"--->"+entry.getValue());

 }


2.用迭代 
Set set = map.entrySet();     
Iterator i = set.iterator();     
while(i.hasNext()){  
    Map.Entry entry1=(Map.Entry)i.next();
    System.out.println(entry1.getKey()+"=="+entry1.getValue());

}


3.用keySet()迭代 
Iterator it=map.keySet().iterator();
while(it.hasNext()){
    String key;
    String value;
    key=it.next().toString();
    value=map.get(key);
    System.out.println(key+"--"+value);
}

你可能感兴趣的:(Java)