Java中 HashMap 的三种遍历方式(精华版)

//(1) for each hm.entrySet()
		HashMap hm = new HashMap();
		Set> entrys = hm.entrySet();
		for (Entry entry : entrys) {
			String key = entry.getKey();
			String value = entry.getValue();
}


//(2) 显示调用hm.entrySet()的集合迭代器
		HashMap hm = new HashMap();
		Iterator> it = hm.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry) it.next();
			String key = entry.getKey();
		    String value = entry.getValue();
		}

//(3) for each hm.keySet(),再调用get获取
		HashMap hm = new HashMap();
		for (String key : hm.keySet()) {
			hm.get(key);					
			}

你可能感兴趣的:(Java中 HashMap 的三种遍历方式(精华版))