标签:keyset set tor 四种 iter str ring out hashmap
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();
}
标签:keyset set tor 四种 iter str ring out hashmap
原文地址:http://www.cnblogs.com/sulaoban/p/6808410.html