Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which BlockingQueue implementation is sorted such that the head has a delay expired for the longest time?

  1. LinkedBlockingQueue

  2. ArrayBlockingQueue

  3. PriorityBlockingQueue

  4. DelayQueue

The correct answer is: DelayQueue

The DelayQueue implementation is specifically designed to hold elements with an associated expiration delay. Therefore, the head of the queue will always be the element with the longest remaining delay. This is not the case for the other BlockingQueue implementations. LinkedBlockingQueue and ArrayBlockingQueue do not have any sorting or priority functionality, so the head could be any element in the queue. PriorityBlockingQueue does have sorting capabilities, but it is based on the natural ordering of the elements or a custom Comparator, not on delay expiration. Thus, the correct answer is D because it is the only implementation that is sorted based on delay expiration time.