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
Which method in the `List` interface returns an unmodifiable view of the list in Java 11?
Answer: Collections.unmodifiableList(list)
`Collections.unmodifiableList()` wraps an existing list in an unmodifiable view, while `List.copyOf()` creates a new independent unmodifiable copy.
What happens when you call `Map.entry(key, value)` in Java 11 and then try to call `setValue()` on the returned entry?
Answer: It throws UnsupportedOperationException
`Map.entry()` returns an immutable `Map.Entry`, so calling `setValue()` throws `UnsupportedOperationException`.
Which `NavigableMap` method returns the greatest key strictly less than the given key, or null if there is no such key?
Answer: lowerKey()
`lowerKey(k)` returns the greatest key strictly less than `k`, while `floorKey(k)` returns the greatest key less than or equal to `k`.
Which of the following correctly describes the behavior of `LinkedHashMap` regarding iteration order?
Answer: Iterates in insertion order by default
`LinkedHashMap` maintains a doubly-linked list to preserve insertion order (or access order if constructed with `accessOrder=true`).
What is the return type of `Collections.frequency(Collection c, Object o)`?
Answer: int
`Collections.frequency()` returns a primitive `int` representing the number of times the specified element appears in the collection.
Which `Deque` method retrieves but does NOT remove the head of the queue, and returns null if the deque is empty?
Answer: peek()
Both `peek()` and `peekFirst()` return null for an empty deque; `peek()` is the `Queue`-interface method equivalent to `peekFirst()` in `Deque`.
When iterating over a `HashSet` and calling `iterator.remove()`, what is the result?
Answer: Removes the element safely without ConcurrentModificationException
Using the iterator's own `remove()` method is the safe way to remove elements during iteration and does not throw `ConcurrentModificationException`.