🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Queue, Deque and PriorityQueue: all 10 questions

Quiz: Queue, Deque and PriorityQueue · Question 9 of 10

What does this print? (code)

What does this print?

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Deque<String> d = new ArrayDeque<>();
        d.offerLast("B");
        d.offerFirst("A");
        d.offerLast("C");
        System.out.println(d.pollLast() + d.pollFirst());
    }
}
  1. A.AC
  2. B.CA
  3. C.BA
  4. D.CB
Answer & explanation

Correct answer: CA

The deque is A, B, C. pollLast removes C and pollFirst removes A, giving "CA".

Can you get the rest right without peeking?

Take the timed Quiz: Queue, Deque and PriorityQueue quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →