Choose maps for keyed lookup, understand access order and String ordering, and review type-safe collections and wrapper conversions in Java SE 25.
Answer: Yes. Map is the appropriate interface to describe a key/value association, but it cannot be instantiated directly. Use an implementation such as Map<String,String> settings = new HashMap<>(). The variable exposes the interface contract, and the object supplies its implementation.
Choose LinkedHashMap when encounter order matters or TreeMap when sorted key navigation matters. Interface-based declarations are useful; the error would be trying to construct Map itself.
Answer: List, Set, and Queue are useful starting families, with Deque extending Queue. In Java SE 25 the full hierarchy also includes SequencedCollection and SequencedSet. List extends SequencedCollection; SortedSet extends SequencedSet, and NavigableSet extends SortedSet. A Set need not be unordered: its implementation can define encounter or sorted order.

ArrayList implements List, HashSet implements Set, and ArrayDeque implements Deque. Map is a separate framework interface and does not extend Collection.
Answer: A Map from serial number to object directly represents that requirement. HashMap provides expected constant-time key lookup with suitable hashes; TreeMap adds sorted and range lookup with logarithmic basic operations. The serial number should have stable equality, often represented by an immutable String.
Putting another object under an equal key replaces the existing mapping. If duplicate serial numbers are invalid, detect them explicitly instead of silently replacing records. A map is part of the framework but is not a Collection subtype.
Answer: String.compareTo compares lexicographically using UTF-16 char values, with a shorter prefix sorting before a longer string sharing that prefix. It is case-sensitive and is not locale-aware alphabetical ordering. For example, uppercase ASCII letters sort before lowercase ASCII letters.
Use an appropriate Collator when human-language collation is required. That is a different comparison rule and may treat strings as comparison-equal even when String.equals does not.
Answer: An access-order LinkedHashMap moves an accessed entry toward the most-recent end. Configure it with the constructor whose third argument is true. In Java SE 25, lastEntry exposes the entry at that end; handle null when the map is empty.
import java.util.LinkedHashMap;
public class RecentParts {
public static void main(String[] args) {
LinkedHashMap<String, String> parts = new LinkedHashMap<>(16, 0.75f, true);
parts.put("SN1", "Pump");
parts.put("SN2", "Valve");
System.out.println(parts.get("SN1"));
System.out.println(parts.keySet());
System.out.println(parts.lastEntry().getKey());
System.out.println(parts.firstEntry().getKey());
}
}
This example has no eviction policy. For a bounded cache, capacity, removal, and concurrency require additional design; LinkedHashMap itself is not synchronized.
Answer: ArrayList grows dynamically and offers collection operations, generic type checking, indexed insertion/removal, and membership searches. An array has fixed length and can store primitives directly. ArrayList stores references, so primitive values require wrapper types.
Convenience does not make every operation faster: contains scans an ordinary ArrayList, and inserting near the front shifts elements. Arrays remain useful for fixed-size or primitive-heavy data.
Answer: For a list of strings, use List<String> names = new ArrayList<>(). The interface states the required operations and the diamond operator infers constructor type arguments. A List<String> rejects adding an Integer at compile time.
Choose a more specific declared type only when its extra operations are needed. Type arguments describe reference types; use List<Integer>, not List<int>.
Answer: Java 5 introduced generics and automatic boxing/unboxing. Earlier collection APIs accepted and returned Object references, so retrieval often needed casts and incorrect element types could fail later. Raw types remain for compatibility, but new code should use parameterized types.
Calling old collections "untyped" is misleading: they still had Java types and runtime type rules. Generics add compile-time element constraints; they are largely implemented through erasure rather than a separate runtime class for every type argument.
Answer: Java 5 introduced automatic boxing and unboxing; Java SE 25 still uses wrapper objects when primitives interact with ordinary generic collections. Boxing converts a primitive to its corresponding wrapper reference, and unboxing extracts the primitive value. Unboxing null throws NullPointerException.
Use equals or primitive comparisons for values. Identity of boxed integers outside the guaranteed small constant range must not be assumed: two boxed 128 values are not guaranteed either identical or distinct. Value-class proposals and implementation optimizations are not a reason to change these standard-language rules.
For example, Integer boxed = 25; int value = boxed; boxes and unboxes. Numeric conversion is separate: assigning an int directly to a Long is not allowed merely because boxing exists; convert to long first.
Answer: Arrays supplies static array algorithms, while Collections supplies list algorithms and List supplies sort. Both reference arrays and lists can use natural ordering or a comparator. Binary search requires the same ordering used to sort the data; a linear membership search does not require sorted input.
These operations are not interchangeable for every Collection. Sets and maps offer their own contracts, and primitive array overloads do not use Comparable objects.
Java SE 25 references: Map, LinkedHashMap, SequencedCollection, SortedSet, NavigableSet, String, Integer, Collator, Arrays.