Map<Integer,String> map = new HashMap<Integer,String>(); //定义map集合
map.put(27, "LinWuZhe"); //map集合添加元素
map.put(39, "TuoYongGang");
map.put(41, "CchengCai");
map.put(42, "XuSanDuo");
Set<Integer> set = map.keySet(); //转换成mset集合
for (Iterator<Integer> it = set.iterator(); it.hasNext();) { //通过迭代器方式取出元素
Integer key = it.next();
String value = map.get(key);
System.out.println(key+":"+value);
} |