JAVAにおけるMapの集合遍歴の方法


もっと読む
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.4
Map 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() ; 
}