private static void test4() {
Map map=new LinkedHashMap();
map.put("1","aaa");
map.put("2", "bbb");
map.put("3", "ccc");
//传统方法2
Set set=map.entrySet();
Iterator it=set.iterator();
while (it.hasNext()) {
Map.Entry entry=(Entry)it.next();
String key=(String) entry.getKey();
String value=(String)entry.getValue();
System.out.print(key+"="+value);
}
//增强for循环取第二种方式
for(Object obj:map.entrySet()){
Map.Entry entry=(Entry)obj;
String key=(String) entry.getKey();
String value=(String)entry.getValue();
System.out.print(key+"="+value);
}
}
|
|