//Test java5 traversal 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 value is: " + o + ",");
System.out.println("value is: " + map.get(o));
}
Running results:
The key value is: 1, the value value is: 11
The key value is: 0, the value value is: 00
The key value is: 2, the value value is: 22
The key value is: 3, the value value is: 33
//Test java5 traversal map
Map<Integer, String> map = new LinkedHashMap<Integer, String>();
map.put(1, "11"); //No need to convert int type to integer
map.put(0, "00");
map.put(2, "22");
map.put(3, "33");
for(Integer o : map.keySet());
System.out.print("key value is: " + o + ","); //There is no need to convert Integer to int.
System.out.println("value is: " + map.get(o));
}
Running results:
The key value is: 1, the value value is: 11
The key value is: 0, the value value is: 00
The key value is: 2, the value value is: 22
The key value is: 3, the value value is: 33
This article comes from the CSDN blog. Please indicate the source when reprinting: http://blog.csdn.net/juyon/archive/2009/12/30/5103935.aspx
-