1Z0-829 Working with Arrays and Collections Practice Question
Given the code snippet: List<String> list = new ArrayList<>(List.of("A","B","C")); list.add("D"); System.out.println(list.size()); What is the result?
⚠ Common exam trap
The trap here is that candidates mistakenly think the list returned by List.of() is directly used, leading them to expect an UnsupportedOperationException, but the ArrayList constructor creates a separate mutable copy, so the add() succeeds.
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
✓
4
The code creates an ArrayList from a fixed-size list returned by List.of() using the ArrayList constructor, which creates a new mutable list containing the elements "A", "B", "C". The subsequent call to list.add("D") successfully appends the element, resulting in a list of size 4. The ArrayList constructor copies the elements, so the original immutable list is not modified.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
5
Why it's wrong here
Only 4 elements are present.
- ✗
UnsupportedOperationException
Why it's wrong here
No exception because the ArrayList is mutable.
- ✓
4
Why this is correct
Correct: the new ArrayList is mutable, so add works, size is 4.
- ✗
Compilation fails
Why it's wrong here
The code compiles successfully.
- ✗
3
Why it's wrong here
The list has 4 elements after adding.
Go deeper
Related to this question
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 →
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.