|
// HashMap作成
HashMap myData = new HashMap();
// データ追加
myData.put( "x", new Integer(1) );
myData.put( "z", new Integer(2) );
myData.put( "y", new Integer(3) );
myData.put( "a", new Integer(4) );
myData.put( "b", new Integer(5) );
// キーのセットビューを取得
Set myKeyset = myData.keySet();
// 列挙用の Iterator を取得
Iterator myIterator = myKeyset.iterator();
// 変更
myData.put( "y", new Integer(30) );
// 列挙
String strKey = null;
Integer nValue = null;
while( myIterator.hasNext() ) {
strKey = (String)myIterator.next();
nValue = (Integer)myData.get(strKey); // 値の取り出し
System.out.println( strKey + " : " + nValue );
}
| |