🎙 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 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());
    }
}
  1. A.1
  2. B.3
  3. C.2
  4. 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 →