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.

HomeCertifications1Z0-829DomainsWorking with Arrays and Collections
1Z0-829Free — No Signup

Working with Arrays and Collections

Practice 1Z0-829 Working with Arrays and Collections questions with full explanations on every answer.

86questions

Start practicing

Working with Arrays and Collections — choose a session length

10 questions~10 min20 questions~20 min30 questions~30 min50 questions~50 min

Free · No account required

1Z0-829 Domains

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 Working with Arrays and Collections questions

10Q20Q30Q50Q

All 1Z0-829 Working with Arrays and Collections questions (86)

Start session

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

1

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

2

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?

3

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

4

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

5

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?

6

Which method of Collection interface returns a primitive int?

7

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?

8

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?

9

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

10

Which TWO are true about the PriorityQueue class?

11

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

12

What is the output of the program?

13

What is the cause of the ClassCastException?

14

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?

15

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?

16

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?

17

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

18

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

19

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?

20

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?

21

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

22

What is the output?

23

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

24

Match each Java collection class to its underlying data structure.

25

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

26

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

27

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

28

When should LinkedList be preferred over ArrayList?

29

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?

30

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

31

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

32

Which is true about CopyOnWriteArrayList?

33

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

34

Which TWO statements are true about creating an unmodifiable List?

35

Which TWO are true about HashSet and TreeSet?

36

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

37

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?

38

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

39

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?

40

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

41

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

42

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

43

What is the output of the above code?

44

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

45

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

46

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

47

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

48

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

49

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

50

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

51

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?

52

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?

53

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

54

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

55

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

56

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

57

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

58

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?

59

Which statement about Collection interface remove methods is correct?

60

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?

61

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

62

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

63

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

64

What is the output?

65

What is the output?

66

What is the output?

67

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?

68

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?

69

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

70

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

71

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?

72

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?

73

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

74

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

75

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

76

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

77

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?

78

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?

79

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?

80

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?

81

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.

82

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?

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?

84

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

85

What is the result of executing this code?

86

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 all 86 Working with Arrays and Collections questions

Other 1Z0-829 exam domains

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

Frequently asked questions

What does the Working with Arrays and Collections domain cover on the 1Z0-829 exam?

The Working with Arrays and Collections domain covers the key concepts tested in this area of the 1Z0-829 exam blueprint published by Oracle. Courseiva provides free domain-focused practice, mock exams, missed-question review, and readiness tracking across all 1Z0-829 domains — no account required.

How many Working with Arrays and Collections questions are in the 1Z0-829 question bank?

The Courseiva 1Z0-829 question bank contains 86 questions in the Working with Arrays and Collections domain. Click any question to see the full explanation and answer breakdown.

What is the best way to practice Working with Arrays and Collections for 1Z0-829?

Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.

Can I practice only Working with Arrays and Collections questions for 1Z0-829?

Yes — the session launcher on this page draws questions exclusively from the Working with Arrays and Collections domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.

Free forever · No credit card required

Track your 1Z0-829 domain progress

Save your results, see per-domain analytics, and get readiness scores — free, for every certification.

Sign Up Free

Free forever · Every certification included

Practice Session

10 questions20 questions30 questions50 questions

Study Resources

All DomainsPractice TestMock ExamFlashcardsStudy Guide