ArraylistをIteratorで全件表示する方法
java
//Listの宣言
List<String> fruits =new ArrayList<>();
fruits.add("リンゴ");
fruits.add("スイカ");
fruits.add("ナシ");
fruits.add("バナナ");
//Iterator<Stromg>の宣言
Iterator<String> it2= fruits.iterator();
//hasNextを使用して値がある場合はループを継続する
while(it2.hasNext()){
//nextを使用して値を取得する
String nation = it2.next();
System.out.println(nation);
}