Collections Framework Flashcards
7 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Collections Framework flashcards as text
What is the default initial capacity of a `HashMap` when constructed with no arguments?
Answer: 16
The default initial capacity of `HashMap` is 16, and it resizes by doubling when the load factor threshold (default 0.75) is exceeded.
Which statement is TRUE about `EnumSet`?
Answer: It is backed by a bit vector for high performance
`EnumSet` is implemented as a bit vector (one or two `long` values), making it extremely fast and memory-efficient for enum-typed elements.
What does the `Map.merge(key, value, remappingFunction)` method do if the key already exists with a non-null value?
Answer: Applies the remapping function to the old and new values
`merge()` calls `remappingFunction.apply(oldValue, newValue)` when the key exists; if the function returns null, the key is removed.
Which of the following correctly uses `Comparator.comparing()` to sort a list of strings by their length?
Answer: Comparator.comparing(String::length)
`Comparator.comparing(String::length)` creates a `Comparator` that extracts the length as the sort key using a method reference.
After calling `iterator.next()` on a `ListIterator`, which method moves the cursor backward?
Answer: iterator.previous()
`ListIterator.previous()` returns the previous element and moves the cursor backward, enabling bidirectional traversal of a list.
Which class would you use to maintain a fixed-size priority queue that automatically discards the lowest-priority elements when full?
Answer: PriorityQueue (with custom size management)
Java's `PriorityQueue` is unbounded, so maintaining a fixed-size bounded priority queue requires manual size checking and removal of the lowest-priority element when the limit is exceeded.
What is the output of `Collections.nCopies(3, "Java")` when its size is queried?
Answer: 3
`Collections.nCopies(3, "Java")` returns an immutable `List` containing 3 references to the string "Java", so its size is 3.