Courseiva
Question 121 of 513
Working with Arrays and CollectionsmediumMultiple SelectObjective-mapped

Two Valid Ways to Create an Immutable List in Java

Which TWO are valid ways to create an immutable List in Java?

Quick Answer

List.of('a', 'b') is correct because it uses the factory method introduced in Java 9 that builds a genuinely immutable list directly, rather than wrapping an already-existing mutable list. Any attempt to add, remove, or set an element on the result throws UnsupportedOperationException, and unlike many older collection APIs, List.of() also rejects null elements outright rather than silently accepting them. It helps to contrast this with Collections.unmodifiableList(), which sits alongside it in this topic area: that method does not create a new immutable list at all, it returns a view wrapping an existing list, so the view itself blocks structural changes, but the underlying list can still be mutated directly and those changes will show up through the view. List.of() has no such backdoor, because there is no separate backing list left for anyone to mutate. When an exam question asks you to identify genuinely immutable list creation, look for factory methods that construct a new list from scratch, such as List.of() and its relatives, rather than methods that merely wrap or restrict access to an existing collection. The naming can be misleading, since both approaches prevent modification through the reference you are given, but only the factory-method approach guarantees the data itself can never change from any angle.

⚠ Common exam trap

Test-takers frequently confuse 'fixed-size' (as in `Arrays.asList()`) with 'immutable', or assume that `Collectors.toList()` returns an immutable list, when in fact it returns a mutable `ArrayList`.

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<>())

`Collections.unmodifiableList()` returns a view of the specified list that cannot be structurally modified; any attempt to add, remove, or set elements will throw an `UnsupportedOperationException`. Option E is correct because `List.of()` (introduced in Java 9) directly creates an immutable list that disallows `null` elements and throws `UnsupportedOperationException` on mutation attempts.

Answer analysis

Option-by-option breakdown

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

  • Stream.of("a").collect(Collectors.toList())

    Why it's wrong here

    Returns mutable list.

  • Collections.unmodifiableList(new ArrayList<>())

    Why this is correct

    Returns immutable view.

  • Arrays.asList("a", "b")

    Why it's wrong here

    Returns fixed-size but mutable list.

  • new ArrayList<>()

    Why it's wrong here

    Mutable list.

  • List.of("a", "b")

    Why this is correct

    Returns immutable list.

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 →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way 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. Which of the following will compile without error and produce an unmodifiable list containing three elements?

hard
  • A.Arrays.asList("A","B","C")
  • B.new ArrayList<>(List.of("A","B","C"))
  • C.List.of("A","B","C")
  • D.Collections.unmodifiableList(new ArrayList<>(List.of("A","B","C")))
  • E.None of the above

Why C: `List.of("A","B","C")` returns an unmodifiable list exactly as required. In Java 9+, `List.of` returns an immutable list; any attempt to modify it throws `UnsupportedOperationException`. Option A, `Arrays.asList`, returns a fixed-size list backed by an array that allows modification via `set()`, so it is not unmodifiable. Option B, `new ArrayList<>(List.of(...))`, creates a mutable ArrayList. Option D, `Collections.unmodifiableList`, returns an unmodifiable view, but the underlying ArrayList is still mutable; modifications to the original list affect the view, so it does not guarantee immutability. Therefore, only C meets the criteria.

Last reviewed: Jun 11, 2026

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.

Loading comments…

Sign in to join the discussion.

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.