JAVAにおけるMapの集合遍歴の方法
744 ワード
もっと読む
1.mapを宣言する:
JDK 1.5
1.mapを宣言する:
Map map = new HashMap();
2.mapに値を置く。注意:mapはkey-valueの形式で保存されている。map.put(”sa”,”dd”);
3.mapから値を取る:String str=map.get("sa").toString();結果は:str = ”dd”;
4.mapを遍歴してkeyとvalueを取得するJDK 1.5
Map m = new HashMap();
for (Object o : map.keySet()) {
map.get(o);
}
JDK 1.4Map map = new HashMap() ;
Iterator it = map.entrySet().iterator() ;
while (it.hasNext())
{
Map.Entry entry = (Map.Entry) it.next() ;
Object key = entry.getKey() ;
Object value = entry.getValue() ;
}