The answer is a runtime exception. The code compiles successfully because `removeIf` is a valid default method on the `Collection` interface, but at runtime, `Arrays.asList` returns a fixed-size list backed directly by the original array, and this list does not support structural modifications like adding or removing elements. When `removeIf` attempts to remove an element, it triggers an `UnsupportedOperationException`. This is a classic trap on the Oracle Certified Professional Java SE 17 Developer 1Z0-829 exam: candidates often assume a compilation error because the list is "fixed," but the compiler sees only the `List` interface contract, not the underlying implementation. The exam tests your understanding that `Arrays.asList` creates a non-resizable view, not an immutable list. Memory tip: think of `Arrays.asList` as a "window" into the array — you can change what you see, but you cannot change the size of the window itself.
1Z0-829 Working with Arrays and Collections Practice Question
This 1Z0-829 practice question tests your understanding of working with arrays and collections. The scenario asks you to isolate a root cause — eliminate options that address a different problem before choosing. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
Exhibit
Refer to the exhibit.
List<String> list = new ArrayList<>();
list.add("A");
List<?> list2 = list;
list2.add("B");
System.out.println(list2);
What is the result of attempting to compile and run the above code?
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Compilation fails
The code attempts to use `removeIf` on a list created with `Arrays.asList`, which returns a fixed-size list backed by the array. The `removeIf` method modifies the list by removing elements, but the fixed-size list does not support structural modification, resulting in an `UnsupportedOperationException` at runtime. However, the question asks for the result of attempting to compile and run, and since the code compiles without errors, the correct answer is 'D. Compilation fails'? Wait — the code does compile; the issue is a runtime exception. The correct answer should be 'E. Runtime exception'. Let me re-evaluate: The code `List<String> list = Arrays.asList("A", "B"); list.removeIf(s -> s.equals("A"));` compiles fine because `removeIf` is a valid method on `List`. At runtime, `Arrays.asList` returns a fixed-size list, and `removeIf` attempts to modify the list structurally, throwing `UnsupportedOperationException`. Therefore, the correct answer is E, not D. I must correct this: The answer is E. The explanation should reflect that.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
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]
Why it's wrong here
Incorrect: the code does not compile.
✗
[A]
Why it's wrong here
Incorrect: the code does not compile.
✗
[B]
Why it's wrong here
Incorrect: the code does not compile.
✓
Compilation fails
Why this is correct
Correct: cannot add non-null to a List<?>.
Related concept
Read the scenario before looking for a memorised answer.
✗
Runtime exception
Why it's wrong here
Incorrect: the error is caught at compile time.
Common exam traps
Common exam trap: answer the scenario, not the keyword
The trap here is that candidates often assume `Arrays.asList` returns a regular `ArrayList` and forget that it returns a fixed-size list that does not support structural modification, leading them to expect a successful removal rather than a runtime exception.
Detailed technical explanation
How to think about this question
`Arrays.asList` returns a fixed-size list backed by the original array, meaning it does not support `add` or `remove` operations that change the size. The `removeIf` method, introduced in Java 8, internally uses an `Iterator` to remove elements, which calls the list's `remove` method, triggering an `UnsupportedOperationException` on fixed-size lists. This is a common pitfall when using `Arrays.asList` for collection operations that modify structure.
KKey Concepts to Remember
Read the scenario before looking for a memorised answer.
Find the constraint that changes the correct option.
Eliminate answers that are true in general but not in this case.
TExam Day Tips
→Watch for words such as best, first, most likely and least administrative effort.
→Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A small business has 20 workstations on the 192.168.1.0/24 network and one public IP from its ISP. The router uses PAT (NAT overload) so all 20 devices share one public address using different source ports. NAT questions test whether you understand the four address terms and which direction each translation applies.
What to study next
Got this wrong? Here's your next step.
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
Working with Arrays and Collections — This question tests Working with Arrays and Collections — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: Compilation fails — The code attempts to use `removeIf` on a list created with `Arrays.asList`, which returns a fixed-size list backed by the array. The `removeIf` method modifies the list by removing elements, but the fixed-size list does not support structural modification, resulting in an `UnsupportedOperationException` at runtime. However, the question asks for the result of attempting to compile and run, and since the code compiles without errors, the correct answer is 'D. Compilation fails'? Wait — the code does compile; the issue is a runtime exception. The correct answer should be 'E. Runtime exception'. Let me re-evaluate: The code `List<String> list = Arrays.asList("A", "B"); list.removeIf(s -> s.equals("A"));` compiles fine because `removeIf` is a valid method on `List`. At runtime, `Arrays.asList` returns a fixed-size list, and `removeIf` attempts to modify the list structurally, throwing `UnsupportedOperationException`. Therefore, the correct answer is E, not D. I must correct this: The answer is E. The explanation should reflect that.
What should I do if I get this 1Z0-829 question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
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 →
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.
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.