Courseiva
Working with Arrays and CollectionseasyMultiple ChoiceObjective-mapped

1Z0-829 Working with Arrays and Collections Practice Question

What is the result of the following code? List<String> list = List.of("A", "B"); list.add("C"); System.out.println(list);

⚠ Common exam trap

Candidates often assume `List.of()` returns a regular mutable `ArrayList` or that the code will simply ignore the `add` call, but the exam tests the specific runtime exception behavior of immutable collections created by factory methods.

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

An exception is thrown at runtime

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.

Answer analysis

Option-by-option breakdown

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

  • [A, B, C]

    Why it's wrong here

    List.of returns immutable list, add not allowed.

  • [A, B]

    Why it's wrong here

    Exception is thrown, not printed.

  • An exception is thrown at runtime

    Why this is correct

    UnsupportedOperationException thrown.

  • Compilation error

    Why it's wrong here

    list.add is a valid method call, compiles.

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 →

How Courseiva writes practice questions · Editorial policy

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.