Switch to Dark Mode

Java Queue and Map Interface

Here are 10 essential multiple-choice questions on Java Queue and Map Interface, covering key concepts.

Last Updated : Apr 2, 2025
Discuss
Comments

Question 1

Which statement about the Queue interface in Java is correct?


  • A

    Queue allows duplicate elements but does not allow null


  • B

    Queue follows LIFO (Last In, First Out) order

  • C

    Queue is an implementation of Deque


  • D

    Queue follows FIFO (First In, First Out) order


Question 2

What is the time complexity of offer(), poll(), and peek() operations in PriorityQueue?

  • A

    O(1), O(1), O(1)

  • B

    O(log n), O(log n), O(1)

  • C

    O(n), O(n), O(n)

  • D

    O(log n), O(n), O(log n)

Question 3

What will be the output of the following code?

Java
import java.util.*;
public class Test {
    public static void main(String[] args) {
        Queue<Integer> queue = new PriorityQueue<>();
        queue.add(30);
        queue.add(10);
        queue.add(50);
        queue.add(20);
        System.out.println(queue.poll());
    }
}


  • A

    10

  • B

    30

  • C

    50

  • D

    20

Question 4

Which of the following statements is true about Deque in Java?

  • A

    Deque allows insertion and removal only from one end

  • B

    Deque can function as both a Queue and a Stack

  • C

    Deque is an abstract class

  • D

    Deque does not allow duplicate elements


Question 5

Which of the following is not a valid implementation of Map in Java?


  • A

    HashMap

  • B

    Hashtable


  • C

    LinkedListMap


  • D

    TreeMap


Question 6

What will be the output of the following code?

Java
import java.util.*;
public class Test {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("A", 10);
        map.put("B", 20);
        map.put("A", 30);
        System.out.println(map.get("A"));
    }
}


  • A

    10

  • B

    20

  • C

    30

  • D

    Compilation Error


Question 7

What is the key difference between HashMap and LinkedHashMap?

  • A

    LinkedHashMap maintains insertion order, while HashMap does not

  • B

    HashMap is slower than LinkedHashMap


  • C

    HashMap allows duplicate keys, while LinkedHashMap does not

  • D

    LinkedHashMap does not allow null keys, while HashMap does


Question 8

What will be the output of the following code?

Java
import java.util.*;
public class Test {
    public static void main(String[] args) {
        Map<Integer, String> map = new LinkedHashMap<>();
        map.put(3, "Three");
        map.put(1, "One");
        map.put(2, "Two");
        System.out.println(map.keySet());
    }
}


  • A

    [1, 2, 3]

  • B

    [3, 1, 2]


  • C

    [2, 1, 3]

  • D

    Unpredictable order

Question 9

Which of the following statements about TreeMap is correct?

  • A

    TreeMap maintains insertion order

  • B

    TreeMap allows null keys

  • C

    TreeMap sorts keys in ascending order by default

  • D

    TreeMap uses a hash table for storage

Question 10

What will be the output of the following code?

Java
import java.util.*;
public class Test {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("X", 100);
        map.put("Y", 200);
        map.put(null, 300);
        System.out.println(map.get(null));
    }
}


  • A

    300

  • B

    null

  • C

    Compilation Error

  • D

    Runtime Exception

There are 10 questions to complete.

Take a part in the ongoing discussion