JavaにおけるHashMapの3つの遍歴方式(エッセンス版)

891 ワード

//(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);					
			}