Map常用四种遍历方式
一:
Map<String,String> map = new HashMap<String,String>();
for(String key:map.keySet()){
System.out.println("key="+key+"value:"+map.get(key));
}
二:
Map<String,String> map = new HashMap<String,String>();
for(String value :map.values()){
System.out.println("value="+value);
}
三:
Map<String,String> map = new HashMap<String,String>();
for(Map.Entry<String, String> entry:map.entrySet()){
System.out.println("key="+entry.getKey()+"value="+entry.getValue());
}
四:
Map<String,String> map = new HashMap<String,String>();
Iterator<Map.Entry<String, String>> iter=map.entrySet().iterator();
while(iter.hasNext()){
Map.Entry<String, String> entry2 = iter.next();
}