Courseiva
Working with Arrays and CollectionseasyMultiple ChoiceObjective-mapped

1Z0-829 Working with Arrays and Collections Practice Question

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 following code? ```java

import java.util.*;

List<String> list = Arrays.asList("A", "B"); list.removeIf(s -> s.startsWith("A")); System.out.println(list); ```

⚠ Common exam trap

A common mistake is to focus on the lambda syntax and assume the code compiles and runs, outputting [B]. However, Arrays.asList returns a fixed-size list, so removeIf throws UnsupportedOperationException at runtime.

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

Runtime exception

The code compiles successfully because `removeIf` is a default method in `Collection` and the predicate is a valid lambda. However, `Arrays.asList` returns a fixed-size list backed by the array, and `removeIf` attempts to modify the list structurally, which throws `UnsupportedOperationException` at runtime. Therefore, the correct answer is E: Runtime exception.

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 list is modified but an exception occurs before any output.

  • [A]

    Why it's wrong here

    Incorrect. The list is modified but an exception occurs before any output.

  • [B]

    Why it's wrong here

    Incorrect. The list is modified but an exception occurs before any output.

  • Compilation fails

    Why it's wrong here

    Incorrect. The code compiles without errors.

  • Runtime exception

    Why this is correct

    Correct. `Arrays.asList` returns a fixed-size list; calling `removeIf` throws `UnsupportedOperationException`.

Quick reference

Cloud Service Model Comparison

ModelYou ManageProvider ManagesExamples
IaaSOS, runtime, apps, dataHardware, hypervisor, networkingEC2, Azure VMs, GCP Compute Engine
PaaSApps and dataOS, runtime, middleware, hardwareElastic Beanstalk, Azure App Service
SaaSData and settings onlyEverything elseMicrosoft 365, Salesforce, Workday
FaaS / ServerlessFunction code onlyInfra, scaling, runtimeLambda, Azure Functions, Cloud Run
CaaSContainers and appsKubernetes, OS, hardwareEKS, AKS, GKE

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.