Courseiva

1Z0-829 · domain

Working with Arrays and Collections

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.

86 questions23 easy34 medium29 hard

Focused practice

Practice Working with Arrays and Collections questions

Scored sessions drawing only from this domain — pick a length below.

Start 20-question practice test →

What this domain covers

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.

Question index

All Working with Arrays and Collections questions (86)

Click any question to see the full explanation, or start a practice session above.

1

An application needs to maintain a set of unique customer IDs (type String) and frequently check if an ID is already present. The set is expected to contain up to 100,000 IDs. The current implementation uses a TreeSet, but performance tests show that the contains() operation is slower than desired. The developer considers switching to a HashSet. However, the business requires that when iterating the set, IDs must appear in sorted order. The developer proposes to convert the HashSet to a sorted list each time iteration is needed. Iteration occurs rarely (once per hour). What is the best approach?

Medium
2

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?

Medium
3

Which of the following collections maintains elements in the order they were inserted?

Easy
4

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

Hard
5

Given ArrayList<Integer> numbers = new ArrayList<>(List.of(1,2,3,4)); Which statement will insert element 10 at index 2?

Easy
6

You are developing a high-frequency trading application that processes a stream of market data ticks. Each tick is an immutable object containing timestamp, price, and volume. The ticks arrive in real time and must be stored in a collection for later analysis. The collection is accessed by multiple threads: one producer thread adds ticks, and multiple consumer threads periodically iterate to compute moving averages. The system must minimize latency for the producer and ensure that consumers see a consistent snapshot of data without interfering with ongoing writes. You initially used a synchronized ArrayList, but profiler results show high contention and poor throughput. You consider the following approaches. Which one best addresses the requirements?

Hard
7

Which TWO statements are true about creating an unmodifiable List?

Medium
8

Which of the following correctly sorts an array of integers (int[] arr) in descending order?

Medium
9

A developer is implementing a cache that stores recent user sessions. The cache should maintain the most recently accessed session at the end, and when the cache reaches its maximum size (1000), it should remove the least recently accessed session (i.e., the oldest). The developer chooses a LinkedList to store sessions, adding new sessions at the end and removing from the front. However, performance is poor because searching for an existing session to update its position requires O(n) linear scan. Which collection should replace the LinkedList to improve performance while maintaining the removal order?

Easy
10

Which TWO are true about the PriorityQueue class?

Hard
11

A Java 17 application uses a HashMap<Integer, List<String>> to group error messages by error code. The map may contain up to 5000 error codes, and each list may contain up to 1000 messages. The application frequently retrieves the list for a given error code and iterates over it. The lists are rarely modified after initial population. The current performance is acceptable, but the team wants to reduce memory footprint. The developer suggests replacing the inner List<String> with an array (String[]), but then iteration would require conversion. Another developer suggests using a TreeMap instead of HashMap to save memory because TreeMap uses less memory per entry? Actually TreeMap has more overhead. Actually HashMap typically has lower overhead than TreeMap. The correct approach: Since lists are rarely modified, consider using List.of to create immutable lists that can be shared? Or use ArrayList with initial capacity to reduce resizing. But the stem says 'reduce memory footprint'. Option C: Use ArrayList with initial capacity to reduce internal array resizing overhead. Option A: Use TreeMap - wrong because TreeMap uses more memory per entry due to tree nodes. Option B: Use array of arrays - not type-safe. Option D: Use LinkedList - higher memory overhead per element. So best is to use ArrayList with proper sizing to minimize wasted space.

Hard
12

Which THREE of the following are valid ways to create a new ArrayList<Integer>? (Select three.)

Medium
13

Which TWO of the following statements about the Collections framework are true?

Medium
14

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

Easy
15

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?

Medium
16

Which TWO statements about the java.util.Collections class are true?

Hard
17

Consider: List<String> list = Arrays.asList("A", "B", "C"); list.add("D"); What is the result?

Medium
18

Which statement about Collection interface remove methods is correct?

Hard
19

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

Easy
20

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

Medium
21

A developer writes the following code using Java 17: List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add(10); What is the result?

Easy
22

What is the output?

Hard
23

Match each Java collection class to its underlying data structure.

Medium
24

Which statement about TreeSet is true when using a custom Comparator that does not define equals() consistently with compare()?

Hard
25

Which TWO statements about Arrays.asList() are true? (Select two.)

Medium
26

Which of the following correctly describes the behavior of the following code? List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); for (String s : list) { if (s.equals("A")) { list.remove(s); } } System.out.println(list);

Hard
27

Given: var list = List.of("A", "B", "C"); list.set(0, "Z"); What is the result?

Medium
28

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?

Medium
29

A developer creates an unmodifiable list via Collections.unmodifiableList(originalList). Later, originalList is modified by adding an element. Which statement is true?

Hard
30

Which of the following will compile without error and produce an unmodifiable list containing three elements?

Hard
31

Which TWO are true about HashSet and TreeSet?

Hard
32

What does the following code print? List<Integer> list = new ArrayList<>(List.of(1,2,3)); list.replaceAll(x -> x * 2); System.out.println(list);

Medium
33

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?

Medium
34

Examine the code: List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); for (String s : list) { list.remove(s); } What is the outcome?

Easy
35

Which TWO statements are true about ArrayList in Java 17? (Choose two.)

Easy
36

Given the code snippet: List<String> list = new ArrayList<>(List.of("A","B","C")); list.add("D"); System.out.println(list.size()); What is the result?

Easy
37

Which two statements are true about the java.util.Comparator and java.lang.Comparable interfaces? (Choose two.)

Medium
38

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); ```

Easy
39

Which is true about CopyOnWriteArrayList?

Hard
40

Which TWO are valid ways to create an immutable list in Java 17? (Choose two.)

Medium
41

What is the output?

Easy
42

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?

Hard
43

What is the output of the following code? List<Integer> list = List.of(0, 1, 2, 3); System.out.println(list.indexOf(0) + " " + list.lastIndexOf(3));

Easy
44

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

Medium
45

Which method of Collection interface returns a primitive int?

Easy
46

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?

Hard
47

Which of the following creates an immutable map with two entries?

Easy
48

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?

Hard
49

Given: Map<String, Integer> map = new HashMap<>(); map.put("x", 10); map.put("y", 20); map.computeIfAbsent("x", k -> 30); map.computeIfPresent("z", (k,v) -> 40); System.out.println(map); What is the output?

Hard
50

Given: Map<Integer, String> map = new HashMap<>(); map.put(1, "one"); map.put(2, "two"); map.entrySet().stream().filter(e -> e.getKey() > 1).forEach(System.out::print); What is output?

Hard
51

A TreeSet<String> is used to store a list of employee names. The set currently contains "Alice", "Bob", "Charlie". What is the output after calling set.add("Bob")?

Medium
52

What will be the result of the following code? Object[] arr = new Integer[5]; arr[0] = "String";

Easy
53

What does the Map.merge() method do if the specified key is absent?

Medium
54

What is the result of executing this code?

Hard
55

Which of the following correctly converts an array of strings to a List?

Easy
56

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?

Medium
57

What is the output of the above code?

Medium
58

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

Medium
59

Which THREE statements are true about HashSet in Java 17? (Choose three.)

Hard
60

Which TWO statements about HashMap are true? (Select two.)

Easy
61

A company's Java 17 application processes large log files and stores word counts. Initially, they used a TreeMap<String, Integer> to maintain sorted word counts. After adding 10 million entries, insertion performance became unacceptably slow. The team switched to a HashMap<String, Integer> for fast insertions, but now they need to produce sorted reports. They are considering two approaches: (1) Keep the HashMap and, when a sorted report is needed, extract all entries into an ArrayList<Map.Entry<String, Integer>> and sort it using Collections.sort with a comparator, or (2) Use a ConcurrentSkipListMap instead. The application is single-threaded, and reports are requested infrequently. What is the best course of action?

Hard
62

Consider: List<Integer> list = new LinkedList<>(); list.add(10); list.add(20); list.add(0,5); System.out.println(list); What is the output?

Medium
63

A HashMap uses a mutable object as a key. After adding the key-value pair, the key's fields are changed such that its hashCode changes. Which statement is true?

Hard
64

A developer is writing a method that takes a Collection<Integer> and returns a List<Integer> containing the same elements in sorted order. The method should not modify the original collection. The developer tries the following code: public List<Integer> sortCollection(Collection<Integer> col) { return col.stream().sorted().collect(Collectors.toList()); } The code compiles and runs, but the team lead says it is not optimal. What improvement should be made?

Medium
65

Which TWO of the following will sort a List<String> in natural (ascending) order?

Easy
66

Given: TreeSet<Integer> set = new TreeSet<>(List.of(3,1,2)); set.add(2); System.out.println(set); What is the output?

Medium
67

A developer needs to sort a List of Employee objects by salary (double) in descending order. Which approach is correct and efficient?

Medium
68

Given: String[] array = {"A", "B"}; List<String> list = Arrays.asList(array); list.set(0, "C"); array[1] = "D"; What is the content of the list?

Easy
69

Given the above Java version, which of the following is NOT a standard Java 17 feature?

Hard
70

Which THREE of the following variable declarations are valid in Java 17?

Hard
71

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?

Hard
72

Which Map implementation guarantees that keys are sorted in their natural order?

Medium
73

What is the output of the program?

Medium
74

A developer writes: ArrayList<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); Object[] arr = list.toArray(); arr[0] = "one"; What happens?

Hard
75

A financial application processes transactions as List<Transaction> objects. The application runs on a server with limited memory (2 GB heap). The development team observes that after processing a large number of transactions (over 10 million), heap usage spikes to near 1.8 GB and garbage collection pauses become frequent (over 5 seconds). The Transaction class is defined as public record Transaction(LocalDateTime timestamp, double amount, String category) {}. The current processing code reads all transactions from a database result set into an ArrayList<Transaction> using a loop with list.add(). Then the list is sorted by timestamp using Collections.sort(list, Comparator.comparing(Transaction::timestamp)). The sorted list is then iterated multiple times to generate various reports. The code runs in a single-threaded context. Which change would most effectively reduce peak memory usage while preserving the sorted report output?

Medium
76

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?

Hard
77

What is the cause of the ClassCastException?

Hard
78

Arrange the steps to create and use a generic method in Java.

Medium
79

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

Hard
80

A team uses a TreeSet with a custom Comparable that returns 0 for objects that are not logically equal (e.g., based on one field but objects differ in another). What is the likely outcome when adding such objects?

Medium
81

When should LinkedList be preferred over ArrayList?

Medium
82

A developer needs to iterate over an ArrayList of integers and remove all elements that are less than 10. Which approach is best to avoid ConcurrentModificationException?

Easy
83

A developer is designing a method that returns an immutable list of strings from an array. Which approach best follows current Java best practices?

Easy
84

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

Easy
85

Which THREE are methods of the Map.Entry interface? (Java 17)

Easy
86

What is the output?

Medium

Frequently asked questions

What does the Working with Arrays and Collections domain cover on the 1Z0-829 exam?
Working with Arrays and Collections questions test whether you can apply the concept in context, not just recognise a definition.
How many questions are in this domain?
This page lists all 86 Working with Arrays and Collections questions in the 1Z0-829 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
What is the best way to practise this domain?
Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
Can I practise only Working with Arrays and Collections questions?
Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.
Oracle Certified Professional Java SE 17 Developer 1Z0-829 Working with Arrays and Collections Practice Questions