memo.xight.org

日々のメモ

HashMap の Key と Value を全取得

Map.Entry を使う

HashMap map = new HashMap();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
map.put("key4", "value4");
map.put("key5", "value5");
TreeMap treeMap = new TreeMap(map);

Set set = treeMap.entrySet();
Iterator it = set.iterator();
while(it.hasNext()) {
	Map.Entry entry = (Map.Entry) it.next();
	System.out.println(entry.getKey());
	System.out.println(entry.getValue());
}


Reference

  Java TIPS
  http://cgi.tripod.co.jp/sky_lark/cgi-bin/tips/ViewTips.cgi?kind=Java