有三种方式,EntrySet----forEach----keySet
前2种比较后,keyset实际要遍历2轮.
******EntrySet********
Iterator it = tempMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); System.out.println("key=" + key + " value=" + value);
}
******EntrySet********
for (Map.Entry entry : tempMap.entrySet()) { String key = entry.getKey().toString(); String value = entry.getValue().toString(); System.out.println("key=" + key + " value=" + value); }