「java入門」java.util.ArrayDeque.iterator()のサンプルコード

Javaコード

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;

public class ArrayListIeratorDemo {

public static void main(String[] args) {
// create an empty array deque with an initial capacity
Deque<Integer> cft = new ArrayDeque<Integer>(8);

// use add() method to add elements in the deque
cft.add(20);
cft.add(32);
cft.add(45);
cft.add(29);

// iterator() is used to print all the elements
// next() returns the next element on each iteration
System.out.println(“printing elements using iterator:");
for(Iterator<Integer> kd = cft.iterator();kd.hasNext();) {
System.out.println(kd.next());
}
}

}

結果

printing elements using iterator:
20
32
45
29

Java

Posted by arkgame