← 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());
}
}
- A.AC
- B.CA
- C.BA
- 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 →