Java Queue and Map Interface

Last Updated :
Discuss
Comments

Question 1

Which class implements both the Queue and Deque interfaces in Java?

  • A

    Stack

  • B

    ArrayList

  • C

    ArrayDeque

  • D

    PriorityQueue

Question 2

What is the main difference between Queue and Deque interfaces?

  • A

    Queue allows LIFO and Deque allows FIFO



  • B

    Queue allows FIFO, Deque allows both FIFO and LIFO

  • C

    Queue does not allow null elements, Deque does

  • D

    Both are same

Question 3

Which queue class maintains natural ordering or uses a Comparator?

  • A

    ArrayDeque


  • B

    PriorityQueue

  • C

    LinkedList

  • D

    Stack

Question 4

What happens if you try to insert null into an ArrayDeque?

  • A

    It gets inserted

  • B

    NullPointerException

  • C

    Compiles but throws at runtime

  • D

    It replaces an existing null

Question 5

Which of the following allows insertion and deletion from both ends?

  • Queue

  • Stack

  • ArrayDeque

  • PriorityQueue

Question 6

What is the time complexity of offer() and poll() operations in a LinkedList-based queue?

  • A

    O(n)

  • B

    O(log n)

  • C

    O(n log n)

  • D

    O(1)

Question 7

Which method of HashMap is used to check if a key exists?

  • A

    containsKey()


  • B

    hasKey()

  • C

    keyExists()

  • D

    isKey()

Question 8

Which of the following is true about LinkedHashMap in Java?

  • A

    It does not maintain the insertion order

  • B

    It allows only unique values

  • C

    It maintains the insertion order

  • D

    It is slower than HashMap in terms of performance

Question 9

What is the time complexity of the get() method in a HashMap?

  • A

    O(log n)

  • B

    O(n)

  • C

    O(1)


  • D

    O(n^2)

Question 10

What does the TreeMap store in Java?

  • A

    Elements in random order

  • B

    Key-value pairs in ascending order of keys

  • C

    Only the keys, sorted

  • D

    Only the values, sorted

There are 16 questions to complete.

Take a part in the ongoing discussion