Java入門–iterator、forとwhileの使い方

Javaコード:

package com.study.startnews24;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListArrLink {
public static void main(String[] args) {
List<Integer>list = new ArrayList<Integer>();
list.add(66);
list.add(77);
list.add(88);
System.out.println(“#####for loop result#####");
for(int i=0;i< list.size();i++){
System.out.println(list.get(i));
}
System.out.println(“#####for loop result###");
for(Integer i:list){
System.out.println(i);
}
System.out.println(“######iterator+while result####");
Iterator<Integer>it=list.iterator();
while(it.hasNext()){
int i=(Integer)it.next();
System.out.println(i);
}
System.out.println(“########iterator+for result #######");
for(Iterator<Integer>iterstartnews24 = list.iterator();iterstartnews24.hasNext();){
int i=(Integer)iterstartnews24.next();
System.out.println(i);
}
}
}

Java

Posted by arkgame