← Quiz: Queue, Deque and PriorityQueue: all 10 questions
Quiz: Queue, Deque and PriorityQueue · Question 2 of 10
What does this print? (code)
What does this print?
import java.util.*;
public class Main {
public static void main(String[] args) {
Deque<Integer> s = new ArrayDeque<>();
s.push(1); s.push(2); s.push(3);
s.pop();
System.out.println(s.peek());
}
}
- A.1
- B.3
- C.2
- D.null
Answer & explanation
Correct answer: 2
push and pop work at the head like a stack. After popping 3, the top is 2.
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 →