โ† All SCJP Flashcard Decks

Java Collections Framework Flashcards

6 cards from real SCJP practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 Java Collections Framework flashcards as text
  1. What does the `PriorityQueue` class use to determine the order of elements?

    Answer: Natural ordering or a Comparator

    `PriorityQueue` orders elements by their natural ordering (Comparable) or by a provided Comparator.

  2. Which interface should be implemented to allow objects to be sorted using `Arrays.sort()` without a Comparator?

    Answer: Comparable

    Implementing `Comparable` and its `compareTo()` method defines the natural ordering used by `Arrays.sort()` and `Collections.sort()`.

  3. What is the key difference between `HashSet` and `LinkedHashSet`?

    Answer: LinkedHashSet maintains insertion order; HashSet does not

    `LinkedHashSet` maintains the insertion order of elements using a linked list, while `HashSet` provides no ordering guarantee.

  4. Which method removes all elements from a List in Java?

    Answer: clear()

    The `clear()` method removes all elements from a collection, leaving it empty.

  5. What exception is thrown when you try to modify a collection while iterating over it with a for-each loop?

    Answer: ConcurrentModificationException

    Modifying a collection's structure during iteration triggers `ConcurrentModificationException` via the fail-fast iterator mechanism.

  6. Which of the following is the correct way to create an unmodifiable view of a List in Java?

    Answer: Collections.unmodifiableList(myList)

    `Collections.unmodifiableList()` wraps a List so that any mutating operations throw `UnsupportedOperationException`.

How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy