Java サンプル - HashMap の走査
以下の例では、Collection クラスの iterator() メソッドを使用してコレクションを走査する方法を示しています。
Main.java ファイル
import java.util.*;
public class Main {
public static void main(String[] args) {
HashMap< String, String> hMap =
new HashMap< String, String>();
hMap.put("1", "1st");
hMap.put("2", "2nd");
hMap.put("3", "3rd");
Collection cl = hMap.values();
Iterator itr = cl.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
}
}
上記のコードの実行出力結果は次のとおりです:
1st 2nd 3rdその他の拡張
Java サンプル