Question 43 of 513
1Z0-829 Working with Arrays and Collections Practice Question
A Java 17 application uses a HashMap<Integer, List<String>> to group error messages by error code. The map may contain up to 5000 error codes, and each list may contain up to 1000 messages. The application frequently retrieves the list for a given error code and iterates over it. The lists are rarely modified after initial population. The current performance is acceptable, but the team wants to reduce memory footprint. The developer suggests replacing the inner List<String> with an array (String[]), but then iteration would require conversion. Another developer suggests using a TreeMap instead of HashMap to save memory because TreeMap uses less memory per entry? Actually TreeMap has more overhead. Actually HashMap typically has lower overhead than TreeMap. The correct approach: Since lists are rarely modified, consider using List.of to create immutable lists that can be shared? Or use ArrayList with initial capacity to reduce resizing. But the stem says 'reduce memory footprint'. Option C: Use ArrayList with initial capacity to reduce internal array resizing overhead. Option A: Use TreeMap - wrong because TreeMap uses more memory per entry due to tree nodes. Option B: Use array of arrays - not type-safe. Option D: Use LinkedList - higher memory overhead per element. So best is to use ArrayList with proper sizing to minimize wasted space.
⚠ Common exam trap
Candidates often assume switching to a different collection type (like TreeMap or LinkedList) will save memory, when in fact the most effective memory optimization is to eliminate wasted internal capacity by using ArrayList with a proper initial capacity.
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
✓
Use ArrayList<String> with initial capacity set to expected list size
Using an ArrayList with an initial capacity set to the expected list size eliminates the overhead of repeated internal array resizing (which wastes memory by leaving unused capacity). Since the lists are rarely modified after initial population, this approach minimizes wasted space without sacrificing iteration performance, unlike the other options.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Replace ArrayList<String> with LinkedList<String>
Why it's wrong here
LinkedList has higher per-element memory overhead.
- ✗
Replace HashMap with TreeMap
Why it's wrong here
TreeMap uses more memory per entry.
- ✗
Replace List<String> with String[]
Why it's wrong here
Reduces flexibility; iteration requires conversion; may not save much memory.
- ✓
Use ArrayList<String> with initial capacity set to expected list size
Why this is correct
Minimizes internal array resizing and waste.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 25, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.