โ† All 1Z0-819 Flashcard Decks

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
  1. Which collection type in Java guarantees that no duplicate elements are stored AND maintains elements in sorted order?

    Answer: TreeSet

    `TreeSet` implements `NavigableSet` backed by a `TreeMap`, which stores elements with no duplicates in their natural or comparator-defined sorted order.

  2. What does `Collections.disjoint(Collection c1, Collection c2)` return when the two collections share at least one common element?

    Answer: false

    `Collections.disjoint()` returns `true` if the collections have NO elements in common, and `false` if they share at least one element.

  3. Which method of `PriorityQueue` removes and returns the head element, or returns null if the queue is empty?

    Answer: poll()

    `poll()` retrieves and removes the head, returning null if empty, while `remove()` also removes the head but throws `NoSuchElementException` if empty.

  4. What is the time complexity of `HashMap.get()` in the average case?

    Answer: O(1)

    `HashMap.get()` has O(1) average-case performance because it computes the hash and directly indexes into the backing array.

  5. Which statement about `CopyOnWriteArrayList` is TRUE?

    Answer: Writes create a fresh copy of the underlying array

    Every mutating operation on `CopyOnWriteArrayList` creates a new copy of the array, making iterators snapshot-safe but memory-intensive.

  6. Which interface does `ArrayDeque` implement that `ArrayList` does NOT?

    Answer: Deque

    `ArrayDeque` implements `Deque` (double-ended queue) allowing efficient insertion and removal at both ends, which `ArrayList` does not support via that interface.

  7. After calling `List.of(1, 2, 3)`, which operation will succeed without throwing an exception?

    Answer: list.contains(2)

    `List.of()` returns an unmodifiable list, so structural mutations like `add`, `set`, and `remove` throw `UnsupportedOperationException`, but read operations like `contains()` work fine.