「Java入門」java.util.Iterator()のサンプル

サンプルコード
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class IteratorDemo {

public static void main(String[] args) {
List<Integer> cftLst = new LinkedList<>(Arrays.asList(11, 21, 6, 3, 8, 12, 1, 3, 7));

Iterator<Integer> cftit = cftLst.iterator();
while (cftit.hasNext()) {
int value = cftit.next();
if (value == 6) {
cftit.remove();
}
}

System.out.println(“結果:" + cftLst);

}

}
結果:[11, 21, 3, 8, 12, 1, 3, 7]

Java

Posted by arkgame