Courseiva
Knowledge + Practice
CertificationsVendorsCareer RoadmapsLabs & ToolsStudy GuidesGlossaryPractice Questions
C
Courseiva

Free IT certification practice questions with explained answers for CCNA, CompTIA, AWS, Azure, Google Cloud, and more.

Certification Practice Questions

CCNA practice questionsSecurity+ SY0-701 practice questionsAWS SAA-C03 practice questionsAZ-104 practice questionsAZ-900 practice questionsCLF-C02 practice questionsA+ Core 1 practice questionsGoogle Cloud ACE practice questionsCySA+ CS0-003 practice questionsNetwork+ N10-009 practice questions
View all certifications →

Product

CertificationsCertification PathsExam TopicsPractice TestsExam Dumps vs Practice TestsStudy HubComparisons

Company

AboutContactEditorial PolicyQuestion Writing PolicyTrust Center

Legal

Privacy PolicyTerms of Service

Courseiva is a free IT certification practice platform offering original exam-style practice questions, detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics for Cisco, CompTIA, Microsoft, AWS, and other technology certifications.

© 2026 Courseiva. Courseiva is operated by JTNetSolutions Ltd. All rights reserved.

Courseiva is an independent certification practice platform and is not affiliated with, endorsed by, or sponsored by Cisco, Microsoft, AWS, CompTIA, Google, ISC2, ISACA, or any other certification vendor. Vendor names and certification marks are used only to identify the exams learners are preparing for.

← Working with Arrays and Collections practice sets

1Z0-829 Working with Arrays and Collections • Complete Question Bank

1Z0-829 Working with Arrays and Collections — All Questions With Answers

Complete 1Z0-829 Working with Arrays and Collections question bank — all 0 questions with answers and detailed explanations.

82
Questions
Free
No signup
Certifications/1Z0-829/Practice Test/Working with Arrays and Collections/All Questions
Question 1mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 2hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 3easymultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 4mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 5hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 6easymultiple choice
Read the full Working with Arrays and Collections explanation →

Which method of Collection interface returns a primitive int?

Question 7mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 8hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 9mediummulti select
Read the full Working with Arrays and Collections explanation →

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

Question 10hardmulti select
Read the full Working with Arrays and Collections explanation →

Which TWO are true about the PriorityQueue class?

Question 11easymulti select
Read the full Working with Arrays and Collections explanation →

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

Question 12mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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
Question 13hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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);
    }
}
Question 14hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 15mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 16mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 17hardmulti select
Read the full Working with Arrays and Collections explanation →

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

Question 18hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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);
```
Question 19mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 20mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 21hardmulti select
Read the full Working with Arrays and Collections explanation →

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

Question 22mediumdrag order
Read the full Working with Arrays and Collections explanation →

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

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5
Question 23mediummatching
Read the full Working with Arrays and Collections explanation →

Match each Java collection class to its underlying data structure.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Resizable array

Doubly linked list

Hash table

Red-black tree

Hash table with buckets

Question 24mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 25easymultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 26hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 27mediummultiple choice
Read the full Working with Arrays and Collections explanation →

When should LinkedList be preferred over ArrayList?

Question 28easymultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 29hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 30mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 31hardmultiple choice
Read the full Working with Arrays and Collections explanation →

Which is true about CopyOnWriteArrayList?

Question 32easymultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 33mediummulti select
Read the full Working with Arrays and Collections explanation →

Which TWO statements are true about creating an unmodifiable List?

Question 34hardmulti select
Read the full Working with Arrays and Collections explanation →

Which TWO are true about HashSet and TreeSet?

Question 35easymulti select
Read the full Working with Arrays and Collections explanation →

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

Question 36easymultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 37mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 38hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 39mediummulti select
Read the full Working with Arrays and Collections explanation →

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

Question 40hardmulti select
Read the full Working with Arrays and Collections explanation →

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

Question 41easymulti select
Read the full NAT/PAT explanation →

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

Question 42mediummultiple choice
Read the full Working with Arrays and Collections explanation →

What is the output of the above code?

Exhibit

Refer to the exhibit.
List<String> list = new ArrayList<>(List.of("a","b","c"));
list.removeIf(s -> s.equals("b"));
System.out.println(list);
Question 43hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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

Network Topology
$ javaversionRefer to the exhibit.openjdk version "17.0.2" 2022-01-18OpenJDK Runtime Environment (build 17.0.2+8-86)
Question 44easymultiple choice
Read the full Working with Arrays and Collections explanation →

What is the result of attempting to compile and run the above code?

Exhibit

Refer to the exhibit.
List<String> list = new ArrayList<>();
list.add("A");
List<?> list2 = list;
list2.add("B");
System.out.println(list2);
Question 45easymultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 46mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 47hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 48mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 49easymultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 50hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 51easymultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 52easymultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 53easymultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 54mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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")?

Question 55mediummultiple choice
Read the full NAT/PAT explanation →

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

Question 56mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 57hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 58hardmultiple choice
Read the full Working with Arrays and Collections explanation →

Which statement about Collection interface remove methods is correct?

Question 59hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 60mediummulti select
Read the full Working with Arrays and Collections explanation →

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

Question 61mediummulti select
Read the full Working with Arrays and Collections explanation →

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

Question 62easymulti select
Read the full Working with Arrays and Collections explanation →

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

Question 63easymultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 64mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 65hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 66mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 67easymultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 68hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 69mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 70easymulti select
Read the full Working with Arrays and Collections explanation →

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

Question 71mediummulti select
Read the full Working with Arrays and Collections explanation →

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

Question 72hardmulti select
Read the full Working with Arrays and Collections explanation →

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

Question 73hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 74mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 75mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 76easymultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 77hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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.

Question 78hardmultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Question 79easymultiple choice
Read the full Working with Arrays and Collections explanation →

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

Question 80mediummulti select
Read the full Working with Arrays and Collections explanation →

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

Question 81hardmultiple choice
Read the full Working with Arrays and Collections explanation →

What is the result of executing this code?

Exhibit

Refer to the exhibit.
```java
import java.util.*;
import java.util.stream.*;
public class Test {
    public static void main(String[] args) {
        List<String> list = List.of("a", "b", "c");
        var result = list.stream()
                         .filter(s -> s.startsWith("b"))
                         .collect(Collectors.toUnmodifiableList());
        result.add("d");
        System.out.println(result);
    }
}
```
Question 82mediummultiple choice
Read the full Working with Arrays and Collections explanation →

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?

Practice tests

Scored 10-question sessions with instant feedback and explanations.

1Z0-829 Practice Test 1 — 10 Questions→1Z0-829 Practice Test 2 — 10 Questions→1Z0-829 Practice Test 3 — 10 Questions→1Z0-829 Practice Test 4 — 10 Questions→1Z0-829 Practice Test 5 — 10 Questions→1Z0-829 Practice Exam 1 — 20 Questions→1Z0-829 Practice Exam 2 — 20 Questions→1Z0-829 Practice Exam 3 — 20 Questions→1Z0-829 Practice Exam 4 — 20 Questions→Free 1Z0-829 Practice Test 1 — 30 Questions→Free 1Z0-829 Practice Test 2 — 30 Questions→Free 1Z0-829 Practice Test 3 — 30 Questions→1Z0-829 Practice Questions 1 — 50 Questions→1Z0-829 Practice Questions 2 — 50 Questions→1Z0-829 Exam Simulation 1 — 100 Questions→

Practice by domain

Each domain maps to a weighted exam section. Focus on the domain where you are weakest.

Handling Date, Time, Text, Numeric and Boolean ValuesControlling Program FlowUtilizing Java Object-Oriented ApproachHandling ExceptionsWorking with Arrays and CollectionsWorking with Streams and Lambda ExpressionsJava Platform Overview and PackagingJava I/O API and Securing Applications

Practice by scenario

Filter questions by type — troubleshooting, exhibit, drag-and-drop, PBQ, ACLs, OSPF, and more.

Browse scenarios→

Continue studying

All Working with Arrays and Collections setsAll Working with Arrays and Collections questions1Z0-829 Practice Hub