Multiple choice java

Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?

  1. java.util.ArrayList

  2. java.util.LinkedHashMap

  3. java.util.HashMap

  4. java.util.TreeMap

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

LinkedHashMap maintains a linked list running through its entries, defining the iteration ordering (insertion-order), which effectively allows retrieval in a FIFO (First-In-First-Out) sequence. HashMap does not guarantee any order, and TreeMap sorts by key natural ordering, not insertion order.

AI explanation

java.util.LinkedHashMap is a Map (so it associates elements with key values) that also maintains a doubly-linked list running through its entries in insertion order, meaning iteration returns entries in the order they were inserted — i.e., first-in, first-out. Plain HashMap gives no ordering guarantee, TreeMap orders by key comparison (sorted order, not insertion order), and ArrayList isn't a Map at all (no key-value association). LinkedHashMap uniquely satisfies both requirements in the question.