โ† 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. Which method must be overridden in a class for its objects to work correctly as HashMap keys?

    Answer: equals() and hashCode()

    HashMap uses `hashCode()` to find the bucket and `equals()` to confirm key equality, so both must be correctly overridden.

  2. Which List implementation provides O(1) add/remove at the ends but O(n) for random access?

    Answer: LinkedList

    `LinkedList` uses a doubly-linked list, giving O(1) insertions at head/tail but O(n) for index-based access.

  3. What is the difference between `Iterator` and `ListIterator` in Java?

    Answer: ListIterator can traverse in both directions; Iterator is forward-only

    `ListIterator` extends `Iterator` with the ability to traverse a list in both forward and backward directions and also supports `add()` and `set()`.

  4. Which collection class is synchronized and considered the thread-safe version of ArrayList?

    Answer: Vector

    `Vector` is a synchronized, thread-safe dynamic array, essentially the legacy thread-safe counterpart to `ArrayList`.

  5. What does the `Collections.sort()` method require from the objects it sorts?

    Answer: Objects must implement Comparable

    `Collections.sort()` requires list elements to implement `Comparable` so their natural ordering can be used.

  6. Which Map implementation maintains keys in their insertion order?

    Answer: LinkedHashMap

    `LinkedHashMap` extends `HashMap` and maintains a linked list of entries in insertion order.

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

Java Collections Framework Flashcards โ€” SCJP Study Cards with Answers