//测试java5遍历map
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("1", "11");
map.put("0", "00");
map.put("2", "22");
map.put("3", "33");
for(String o : map.keySet()){
System.out.print("key值为:" + o + ",");
System.out.println("value值为:" + map.get(o));
}
运行结果:
key值为:1,value值为:11
key值为:0,value值为:00
key值为:2,value值为:22
key值为:3,value值为:33
//测试java5遍历map
Map<Integer, String> map = new LinkedHashMap<Integer, String>();
map.put(1, "11"); //不用把int型转换成integer咯
map.put(0, "00");
map.put(2, "22");
map.put(3, "33");
for(Integer o : map.keySet());
System.out.print("key值为:" + o + ","); //不用把Integer转换成int咯
System.out.println("value值为:" + map.get(o));
}
运行结果:
key值为:1,value值为:11
key值为:0,value值为:00
key值为:2,value值为:22
key值为:3,value值为:33
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/juyon/archive/2009/12/30/5103935.aspx
-