Java Queue and Map Interface

Last Updated :
Discuss
Comments

Question 1

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

  • Stack

  • ArrayList

  • ArrayDeque

  • PriorityQueue

Question 2

What is the main difference between Queue and Deque interfaces?

  • Queue allows LIFO and Deque allows FIFO



  • Queue allows FIFO, Deque allows both FIFO and LIFO

  • Queue does not allow null elements, Deque does

  • Both are same

Question 3

Which queue class maintains natural ordering or uses a Comparator?

  • ArrayDeque


  • PriorityQueue

  • LinkedList

  • Stack

Question 4

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

  • It gets inserted

  • NullPointerException

  • Compiles but throws at runtime

  • 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?

  • O(n)

  • O(log n)

  • O(n log n)

  • O(1)

Question 7

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

  • containsKey()


  • hasKey()

  • keyExists()

  • isKey()

Question 8

Which of the following is true about LinkedHashMap in Java?

  • It does not maintain the insertion order


  • It allows only unique values

  • It maintains the insertion order

  • It is slower than HashMap in terms of performance

Question 9

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

  • O(log n)

  • O(n)

  • O(1)


  • O(n^2)

Question 10

What does the TreeMap store in Java?

  • Elements in random order

  • Key-value pairs in ascending order of keys

  • Only the keys, sorted

  • Only the values, sorted

There are 16 questions to complete.

Take a part in the ongoing discussion