โ† 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. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.