上面是两种方法,,接下来是两种方法
Map<String, Integer> m = new HashMap<String, Integer>();
m.put("a", 2);
m.put("b", 1);
m.put("c", 3);
Set<Map.Entry<String, Integer>> entry = m.entrySet();
Iterator<Map.Entry<String, Integer>> it = entry.iterator();
while (it.hasNext()) {
Map.Entry<java.lang.String, java.lang.Integer> en = it.next();
System.out.println(en.getKey() + " = " + en.getValue());
}
for (Entry<String, Integer> en : m.entrySet()) {
System.out.println(en.getKey() + "=" + en.getValue());
} |