Java Learner logo
← Back to all exercises

Collections

Deque pushes vs polls

Determine the three lines printed after mixing add, push, and poll operations.

Collections

Deque pushes vs polls

IntermediateAwaiting attempt

Determine the three lines printed after mixing add, push, and poll operations.

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

public class Main {
    public static void main(String[] args) {
        Deque<String> queue = new ArrayDeque<>();
        queue.add("A");
        queue.addFirst("B");
        queue.offerLast("C");
        queue.pollFirst();
        queue.push("D");

        System.out.println(queue.pop());
        System.out.println(queue.removeLast());
        System.out.println(queue.peek());
    }
}