Map迭代方式,Map迭代,Map循环
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2015年7月2日 09:19:11 星期四
public static void main(String[] args) {
HashMap map = new HashMap();
map.put("a", "is a.");
map.put("b", "is b.");
map.put("c", "is c.");
map.put("d", "is d.");
map.put("a", "is aaaaaaaaaaaaaaaaaaaaa.");//键不变,a的值改变
//map迭代方式一
Set set = map.keySet();
for(Iterator iterator = set.iterator();iterator.hasNext();){
String key = (String) iterator.next();
String value = (String) map.get(key);
System.out.println("key="+key+", value="+value);
}
System.out.println("--------------------------------------");
//map迭代方式二
Set s = map.entrySet();
for(Iterator it = s.iterator();it.hasNext();){
Map.Entry en = (Map.Entry) it.next();
System.out.println("key="+en.getKey()+", value="+en.getValue());
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2015年7月2日 09:19:11 星期四