「java入門」java.util.ArrayDeque.peek()のサンプルコード
javaコード
import java.util.ArrayDeque;
import java.util.Deque;
public class ArrayListPeekDemo {
public static void main(String[] args) {
// create an empty array deque with an initial capacity
Deque<Integer> chang = new ArrayDeque<Integer>(10);
// use add() method to add elements in the deque
chang.add(44);
chang.add(37);
chang.add(28);
chang.add(98);
// this will retrieve head of the queue
int retval = chang.peek();
System.out.println(“Retrieved Element is " + retval);
// printing all the elements available in deque
for (Integer numVal : chang) {
System.out.println(“Value = " + numVal);
}
}
}
結果
Retrieved Element is 44
Value = 44
Value = 37
Value = 28
Value = 98