Skip to content
Sharp

Collections · interview question

In a queue implemented with ArrayDeque, what will the following code output? ArrayDeque<Integer> queue = new ArrayDeque<>(); queue.offer(1); queue.offer(2); queue.offer(3); System.out.println(queue.poll());?

Multiple choiceMediumchapter-4-curatedpremiumcollectionsqueue-and-deque-basics
java
ArrayDeque<Integer> queue = new ArrayDeque<>();
queue.offer(1);
queue.offer(2);
queue.offer(3);
System.out.println(queue.poll());
Choose one answer
Answer and explanation

Correct answer

A. 1

Why

The poll() method retrieves and removes the head of the queue, which is the first element added. Thus, it will output '1'.

Test yourself on Collections

A free test with instant, explained results. No account needed.

Start free test
All Collections questions →