1Z0-829 Working with Arrays and Collections Practice Question
A method returns a List<Integer>. The caller wants to ensure the list cannot be modified. Which is the best approach?
⚠ Common exam trap
Many candidates confuse 'unmodifiable view' with 'immutable copy' and may pick options like `Arrays.asList()` or `clone()` thinking they prevent modification, but those still allow structural changes or mutation through the backing array.
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
✓
return Collections.unmodifiableList(list);
`Collections.unmodifiableList()` returns a read-only view of the specified list. Any attempt to modify the returned list (e.g., via `add`, `remove`, `set`) will throw an `UnsupportedOperationException`. This is the standard, recommended approach in the Java Collections Framework to provide an unmodifiable wrapper without copying the underlying data.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
return Arrays.asList(list.toArray());
Why it's wrong here
Returns a mutable list backed by array.
- ✗
return new ArrayList<>(list);
Why it's wrong here
Mutable copy.
- ✗
return (List<Integer>) list.clone();
Why it's wrong here
clone() returns mutable list.
- ✓
return Collections.unmodifiableList(list);
Why this is correct
Returns an unmodifiable view.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.