「Java入門」HashMap(keysetとentryset)で要素の格納と取り出す方法のまとめ

Javaコード:
方法1 entrySet
Map map = HashMap();
Iterator iter = map.entrySet().iterator();
(iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}

方法2 keySet
Map map = HashMap();
Iterator iter = map.keySet().iterator();
(iter.hasNext()) {
Object key = iter.next();
Object val = map.get(key);
}

方法1をお勧めします

Java

Posted by arkgame