Question 206 of 513
Valid Ways to Create an Immutable List
Which TWO are valid ways to create an immutable list in Java 17? (Choose two.)
Quick Answer
List.copyOf(Arrays.asList('a', 'b')) is correct because List.copyOf() takes an existing collection and produces a brand-new, independent immutable list from its contents, rather than simply wrapping or restricting access to the collection you pass in. That distinction matters: once the copy is made, changes to the original source collection have no effect on the immutable list you now hold, and any attempt to modify the returned list directly is rejected. List.copyOf() also enforces the same null-hostility as the rest of the newer immutable-collection factory methods, throwing NullPointerException if any element in the source is null, so it is not just immutable but also stricter about what it will accept in the first place. It is useful to contrast this with Collections.unmodifiableList(), which the same topic covers: that method returns a view over the original mutable list, so the view blocks direct modification, but the underlying list can still be changed elsewhere, and those changes leak through the view, whereas List.copyOf() severs that connection entirely by copying the data. When an exam question asks you to identify a method that produces a truly independent, immutable snapshot of existing data rather than a restricted window onto mutable data, List.copyOf() alongside List.of() is the pattern to reach for.
⚠ Common exam trap
Oracle often tests the distinction between an unmodifiable view (which can be circumvented if the backing list is accessible) and a truly immutable list (which cannot be changed by any means), and candidates mistakenly think `Arrays.asList()` or `new ArrayList<>()` are immutable.
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
✓
Collections.unmodifiableList(new ArrayList<>(List.of("a", "b")))
`Collections.unmodifiableList()` wraps a mutable list in an unmodifiable view, preventing any structural modifications. Option D is correct because `List.copyOf()` creates an immutable list from an existing collection, throwing `NullPointerException` if any element is null. Both produce lists that cannot be modified after creation.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Arrays.asList("a", "b")
Why it's wrong here
Returns fixed-size but mutable via set.
- ✗
List.of(List.of("a", "b"))
Why it's wrong here
Creates a list containing a list, not a flat immutable list.
- ✓
Collections.unmodifiableList(new ArrayList<>(List.of("a", "b")))
Why this is correct
Wraps list to be unmodifiable.
- ✓
List.copyOf(Arrays.asList("a", "b"))
Why this is correct
List.copyOf returns an immutable list.
- ✗
new ArrayList<>(List.of("a", "b"))
Why it's wrong here
Creates a mutable ArrayList.
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 →
Same concept, more angles
3 more ways this is tested on 1Z0-829
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A method returns a List<Integer>. The caller wants to ensure the list cannot be modified. Which is the best approach?
medium- A.return Arrays.asList(list.toArray());
- B.return new ArrayList<>(list);
- C.return (List<Integer>) list.clone();
- ✓ D.return Collections.unmodifiableList(list);
Why D: `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.
Variation 2. What is the result of executing this code?
hard- A.Compilation error
- B.[b]
- ✓ C.Runtime exception
- D.[b, d]
Why C: The code uses `Collectors.toUnmodifiableList()` which returns an unmodifiable list. Attempting to add an element to this list throws an `UnsupportedOperationException` at runtime. Therefore, option C (Runtime exception) is correct.
Variation 3. What is the result of the following code? List<String> list = List.of("A", "B"); list.add("C"); System.out.println(list);
easy- A.[A, B, C]
- B.[A, B]
- ✓ C.An exception is thrown at runtime
- D.Compilation error
Why C: The `List.of()` factory method returns an immutable list. Calling `add()` on an immutable list throws an `UnsupportedOperationException` at runtime, so the code does not compile or run successfully. Option C is correct because the exception is thrown when the `add` method is invoked.
Last reviewed: Jun 30, 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.