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.
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.
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?
Medium2A 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?
Medium3Which of the following collections maintains elements in the order they were inserted?
Easy4Which THREE statements are true about the java.util.Collection and java.util.stream.Stream APIs? (Choose three.)
Hard5Given ArrayList<Integer> numbers = new ArrayList<>(List.of(1,2,3,4)); Which statement will insert element 10 at index 2?
Easy6You 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?
Hard7Which TWO statements are true about creating an unmodifiable List?
Medium8Which of the following correctly sorts an array of integers (int[] arr) in descending order?
Medium9A 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?
Easy10Which TWO are true about the PriorityQueue class?
Hard11A 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.
Hard12Which THREE of the following are valid ways to create a new ArrayList<Integer>? (Select three.)
Medium13Which TWO of the following statements about the Collections framework are true?
Medium14What is the result of the following code? List<String> list = List.of("A", "B"); list.add("C"); System.out.println(list);
Easy15A 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?
Medium16Which TWO statements about the java.util.Collections class are true?
Hard17Consider: List<String> list = Arrays.asList("A", "B", "C"); list.add("D"); What is the result?
Medium18Which statement about Collection interface remove methods is correct?
Hard19Which THREE are valid ways to iterate over a Map<String, Integer>?
Easy20Which TWO are valid ways to create an immutable List in Java?
Medium21A 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?
Easy22What is the output?
Hard23Match each Java collection class to its underlying data structure.
Medium24Which statement about TreeSet is true when using a custom Comparator that does not define equals() consistently with compare()?
Hard25Which TWO statements about Arrays.asList() are true? (Select two.)
Medium26Which 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);
Hard27Given: var list = List.of("A", "B", "C"); list.set(0, "Z"); What is the result?
Medium28A 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?
Medium29A developer creates an unmodifiable list via Collections.unmodifiableList(originalList). Later, originalList is modified by adding an element. Which statement is true?
Hard30Which of the following will compile without error and produce an unmodifiable list containing three elements?
Hard31Which TWO are true about HashSet and TreeSet?
Hard32What does the following code print? List<Integer> list = new ArrayList<>(List.of(1,2,3)); list.replaceAll(x -> x * 2); System.out.println(list);
Medium33A 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?
Medium34Examine the code: List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); for (String s : list) { list.remove(s); } What is the outcome?
Easy35Which TWO statements are true about ArrayList in Java 17? (Choose two.)
Easy36Given 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?
Easy37Which two statements are true about the java.util.Comparator and java.lang.Comparable interfaces? (Choose two.)
Medium38What 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); ```
Easy39Which is true about CopyOnWriteArrayList?
Hard40Which TWO are valid ways to create an immutable list in Java 17? (Choose two.)
Medium41What is the output?
Easy42A 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?
Hard43What 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));
Easy44A developer needs to remove elements from an ArrayList<String> while iterating over it. Which approach is safest and avoids ConcurrentModificationException?
Medium45Which method of Collection interface returns a primitive int?
Easy46Given: 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?
Hard47Which of the following creates an immutable map with two entries?
Easy48Given: 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?
Hard49Given: 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?
Hard50Given: 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?
Hard51A 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")?
Medium52What will be the result of the following code? Object[] arr = new Integer[5]; arr[0] = "String";
Easy53What does the Map.merge() method do if the specified key is absent?
Medium54What is the result of executing this code?
Hard55Which of the following correctly converts an array of strings to a List?
Easy56A 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?
Medium57What is the output of the above code?
Medium58A method returns a List<Integer>. The caller wants to ensure the list cannot be modified. Which is the best approach?
Medium59Which THREE statements are true about HashSet in Java 17? (Choose three.)
Hard60Which TWO statements about HashMap are true? (Select two.)
Easy61A 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?
Hard62Consider: List<Integer> list = new LinkedList<>(); list.add(10); list.add(20); list.add(0,5); System.out.println(list); What is the output?
Medium63A 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?
Hard64A 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?
Medium65Which TWO of the following will sort a List<String> in natural (ascending) order?
Easy66Given: TreeSet<Integer> set = new TreeSet<>(List.of(3,1,2)); set.add(2); System.out.println(set); What is the output?
Medium67A developer needs to sort a List of Employee objects by salary (double) in descending order. Which approach is correct and efficient?
Medium68Given: String[] array = {"A", "B"}; List<String> list = Arrays.asList(array); list.set(0, "C"); array[1] = "D"; What is the content of the list?
Easy69Given the above Java version, which of the following is NOT a standard Java 17 feature?
Hard70Which THREE of the following variable declarations are valid in Java 17?
Hard71Given: 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?
Hard72Which Map implementation guarantees that keys are sorted in their natural order?
Medium73What is the output of the program?
Medium74A 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?
Hard75A 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?
Medium76Given: 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?
Hard77What is the cause of the ClassCastException?
Hard78Arrange the steps to create and use a generic method in Java.
Medium79What is the result of executing the code in the exhibit?
Hard80A 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?
Medium81When should LinkedList be preferred over ArrayList?
Medium82A 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?
Easy83A developer is designing a method that returns an immutable list of strings from an array. Which approach best follows current Java best practices?
Easy84Which interface provides the ability to store key-value pairs and allows null keys?
Easy85Which THREE are methods of the Map.Entry interface? (Java 17)
Easy86What is the output?
MediumOther domains
All 1Z0-829 exam domains
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.