Courseiva
Working with Arrays and CollectionshardMultiple ChoiceObjective-mapped

1Z0-829 Working with Arrays and Collections Practice Question

Given: Set<Integer> set = new HashSet<>(List.of(1,2,3)); List<Integer> list = new ArrayList<>(set); Collections.sort(list); System.out.println(list); What is the output?

⚠ Common exam trap

Watch out — candidates often assume HashSet preserves insertion order (like LinkedHashSet) and thus expect unsorted output, forgetting that Collections.sort() explicitly sorts the list into ascending order.

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

[1,2,3]

The code creates a HashSet from a List of 1, 2, 3, then copies it into an ArrayList. HashSet does not guarantee order, but Collections.sort() sorts the list in natural ascending order (1, 2, 3). The output is [1,2,3], making option C correct.

Answer analysis

Option-by-option breakdown

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

  • [3,2,1]

    Why it's wrong here

    Incorrect: sorting produces ascending order.

  • Compilation fails

    Why it's wrong here

    The code compiles successfully.

  • [1,2,3]

    Why this is correct

    Correct: after sorting, the list is in ascending order.

  • [1,2]

    Why it's wrong here

    Incorrect: all three elements are present.

  • [1,3,2]

    Why it's wrong here

    Incorrect: sorted list is [1,2,3].

About these practice questions

Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.