1Z0-829 · topic practice

Working with Arrays and Collections practice questions

Practise Oracle Certified Professional Java SE 17 Developer 1Z0-829 Working with Arrays and Collections practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.

Courseiva uses original exam-style practice questions designed for learning and revision. The goal is to understand the concepts, recognise exam patterns, and improve through explanations — not memorise copied exam dumps.

Reviewed byJohnson Ajibi· MSc IT Security
20 questionsDomain: Working with Arrays and Collections

What the exam tests

What to know about Working with Arrays and Collections

Working with Arrays and Collections questions test whether you can apply the concept in context, not just recognise a definition.

How the topic appears in realistic exam-style scenarios.

Which detail in the question changes the correct answer.

How to eliminate plausible but wrong options.

How to connect the question back to the wider exam objective.

Watch out for

Common Working with Arrays and Collections exam traps

  • Answering from memory before reading the full scenario.
  • Missing a constraint such as cost, availability, security, scope or command context.
  • Choosing a broad answer when the question asks for the most specific fix.
  • Ignoring why the wrong options are tempting.

Practice set

Working with Arrays and Collections questions

20 questions · select your answer, then reveal the explanation

A developer needs to remove elements from an ArrayList<String> while iterating over it. Which approach is safest and avoids ConcurrentModificationException?

Given: HashSet<String> set = new HashSet<>(); set.add("A"); set.add("B"); set.add("C"); set.add("A"); System.out.println(set.size()); What is the output?

Which interface provides the ability to store key-value pairs and allows null keys?

A method returns a List<Integer>. The caller wants to ensure the list cannot be modified. Which is the best approach?

Given: TreeSet<Integer> ts = new TreeSet<>(Comparator.reverseOrder()); ts.add(10); ts.add(5); ts.add(20); ts.add(15); System.out.println(ts.first()); What is the result?

Which method of Collection interface returns a primitive int?

A developer writes: List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add(1, "C"); System.out.println(list); What is the output?

Given: Map<String, Integer> map = new HashMap<>(); map.put("A", 1); map.put("B", 2); map.merge("A", 3, (v1, v2) -> v1 + v2); System.out.println(map.get("A")); What is the result?

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

Which TWO are true about the PriorityQueue class?

Which THREE are valid ways to iterate over a Map<String, Integer>?

What is the output of the program?

Exhibit

Refer to the exhibit.

$ cat list.txt
A
B
C
D

$ cat ListDemo.java
import java.util.*;
import java.util.stream.*;
public class ListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>(List.of("A", "B", "C", "D"));
        list.removeIf(s -> s.compareTo("C") > 0);
        System.out.println(list);
    }
}

$ javac ListDemo.java && java ListDemo

What is the cause of the ClassCastException?

Exhibit

Refer to the exhibit.

Error log:
Exception in thread "main" java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String
    at com.example.Cache.get(Cache.java:12)
    at com.example.Main.main(Main.java:10)

Source code:
public class Cache {
    private Map<String, Object> store = new HashMap<>();
    public <T> T get(String key, Class<T> type) {
        Object value = store.get(key);
        return type.cast(value);
    }
}

public class Main {
    public static void main(String[] args) {
        Cache cache = new Cache();
        cache.store.put("age", 30);
        String age = cache.get("age", String.class);
        System.out.println(age);
    }
}

A financial application processes transactions in batches. Each transaction is represented as a Transaction object with fields: long id, BigDecimal amount, LocalDateTime timestamp. Transactions are stored in a List<Transaction> in the order they arrive. The system needs to frequently check if a transaction with a specific id exists, and also needs to iterate through transactions in chronological order. The list currently contains millions of transactions, and the existence check is becoming a performance bottleneck because it currently uses a linear search. The system must also maintain insertion order for iteration. Which approach best improves the performance of the existence check while maintaining the required iteration order?

A web server logs user sessions. Each session has a unique session ID (String) and a last access time (long). The system needs to evict sessions that have been inactive for more than 30 minutes. The current implementation uses a HashMap<String, Long> to store session IDs and last access times. A scheduled task iterates over all entries and removes those where currentTime - lastAccess > 30 minutes. However, this iteration is becoming slow as the number of sessions grows (millions). The developer wants to improve the eviction performance without affecting the O(1) put and get operations. Which approach should be taken?

A developer is implementing a custom sort for a list of Employee objects. The Employee class has fields: String name, int age. The list must be sorted first by name (ascending, case-insensitive), then by age (descending). Which Comparator implementation correctly achieves this?

Which THREE statements are true about the java.util.Collection and java.util.stream.Stream APIs? (Choose three.)

What is the result of executing the code in the exhibit?

Exhibit

Refer to the exhibit.
```
List<String> list = new ArrayList<>(List.of("A", "B", "C"));
for (String s : list) {
    if (s.equals("B")) {
        list.remove(s);
    }
}
System.out.println(list);
```

A developer is working on a high-performance trading application that processes market data. The system needs to maintain a sorted list of order IDs (Long values) that are frequently inserted and removed. The current implementation uses a TreeSet<Long> to store the order IDs. The application is experiencing performance degradation under high load, and profiling shows that the TreeSet operations are the bottleneck. The developer considers replacing the TreeSet with a data structure that offers O(log n) insertion and removal but also supports O(log n) indexed access (e.g., get by index) for batch processing. Which of the following should the developer choose to improve performance while maintaining the sorted order and adding indexed access?

A developer needs to filter a list of transactions where the amount is greater than 100 and collect the results into a new list. Which approach is best practice for readability and performance?

Free account

Track your progress over time

Create a free account to save your results and see which topics improve across sessions.

Focused Working with Arrays and Collections sessions

Start a Working with Arrays and Collections only practice session

Every question in these sessions is drawn from the Working with Arrays and Collections domain — nothing else.

Related practice questions

Related 1Z0-829 topic practice pages

Move into related areas when this topic feels solid.

Frequently asked questions

What does the 1Z0-829 exam test about Working with Arrays and Collections?
Working with Arrays and Collections questions test whether you can apply the concept in context, not just recognise a definition.
How should I use these practice questions?
Select your answer before revealing the explanation. Then read why each option is right or wrong — this active recall approach builds retention far faster than re-reading notes.
Can I practise just Working with Arrays and Collections questions in a focused session?
Yes — the session launcher on this page draws every question from the Working with Arrays and Collections domain. Use a 10-question session first to gauge your baseline, then move to 20 or 30 once the weak spots are clear.
Where can I practise other 1Z0-829 topics?
Use the topic links above to move to related areas, or go back to the 1Z0-829 question bank to see all topics.
Are these real exam questions or dumps?
These are original practice questions written to test the same concepts the 1Z0-829 exam covers. They are not copied from any real exam or dump site.