//最常規的一種遍歷方法,最常規就是最經常使用的,雖然不復雜,但很重要,這是咱們最熟悉的,就很少說了!! public static void work(Map<String, Student> map) { Collection<Student> c = map.values(); Iterator it = c.iterator(); for (; it.hasNext();) { System.out.println(it.next()); } } //利用keyset進行遍歷,它的優勢在於能夠根據你所想要的key值獲得你想要的 values,更具靈活性!! public static void workByKeySet(Map<String, Student> map) { Set<String> key = map.keySet(); for (Iterator it = key.iterator(); it.hasNext();) { String s = (String) it.next(); System.out.println(map.get(s)); } } //比較複雜的一種遍歷在這裏,呵呵~~他很暴力哦,它的靈活性太強了,想獲得什麼就能獲得什麼~~ public static void workByEntry(Map<String, Student> map) { Set<Map.Entry<String, Student>> set = map.entrySet(); for (Iterator<Map.Entry<String, Student>> it = set.iterator(); it.hasNext();) { Map.Entry<String, Student> entry = (Map.Entry<String, Student>) it.next(); System.out.println(entry.getKey() + "--->" + entry.getValue()); } }