Courseiva
Working with Arrays and CollectionseasyMultiple ChoiceObjective-mapped

1Z0-829 Working with Arrays and Collections Practice Question

A developer is implementing a cache that stores recent user sessions. The cache should maintain the most recently accessed session at the end, and when the cache reaches its maximum size (1000), it should remove the least recently accessed session (i.e., the oldest). The developer chooses a LinkedList to store sessions, adding new sessions at the end and removing from the front. However, performance is poor because searching for an existing session to update its position requires O(n) linear scan. Which collection should replace the LinkedList to improve performance while maintaining the removal order?

⚠ Common exam trap

Test-takers frequently choose HashSet for speed but forget that order is required, or choose TreeSet thinking sorted order helps, but neither maintains insertion/access order for LRU eviction.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

LinkedHashSet

LinkedHashSet (C) maintains insertion order (which can be used to represent access order if reinserted on access) and provides O(1) average-time complexity for add, remove, and contains operations. By removing and re-adding a session upon access, it moves to the end, and the oldest (first inserted) can be removed from the front when the size exceeds 1000, solving the O(n) scan problem of LinkedList.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • TreeSet

    Why it's wrong here

    Sorted order, not access order.

  • HashSet

    Why it's wrong here

    No order guarantee.

  • LinkedHashSet

    Why this is correct

    O(1) add, remove, contains; maintains insertion order; can reinsert to move to end.

  • ArrayList

    Why it's wrong here

    Removal from front is O(n).

About these practice questions

One of 513 original 1Z0-829 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.