Study guide
6.3 Collections Framework: List, Set, Queue, and Deque APIs
Oracle Java SE 17 Developer Certified Professional 1Z0-829
Track your progress as you read
Finished sections get a check mark.
1 Introduction: The 1Z0-829 Exam
About the Java SE 17 Developer (1Z0-829) Exam
2 Chapter 1: Java Fundamentals & Language Basics
1.1 Primitive Types, Literals, Wrapper Classes, and Type Promotion/Casting 1.2 Local Variable Type Inference (`var`) Rules and Scoping 1.3 Operators, Precedence, Evaluation Order, and Short-Circuit Evaluation 1.4 Text Blocks, String Immutability, and StringBuilder APIs
3 Chapter 2: Program Flow & Decision Constructs
2.1 Conditional Branching with if/else and the Ternary Operator 2.2 Switch Statements and Switch Expressions 2.3 Iteration Constructs, Loop Control, and Branching Labels
4 Chapter 3: Object-Oriented Design & Class Mechanics
3.1 Class Declarations, Field/Method Signatures, and Access Modifiers 3.2 Constructors, Overloading, Initialization Order, and Garbage Collection 3.3 Inheritance, Method Overriding, Polymorphism, and `super`/`this` 3.4 Abstract Classes, Static Members, and Object Methods (`equals`, `hashCode`, `toString`)
5 Chapter 4: Advanced OOP: Interfaces, Records & Sealed Types
4.1 Interface Architecture: Default, Static, and Private Methods 4.2 Enumerations: Constants, Constructors, Methods, and Custom Bodies 4.3 Records: Canonical/Compact Constructors, Components, and Immutability 4.4 Sealed Classes and Interfaces: `permits`, Hierarchy Constraints, and Modifiers
6 Chapter 5: Pattern Matching & Nested Types
5.1 Pattern Matching for `instanceof` and Flow Scoping Mechanics 5.2 Nested Types: Member Inner, Static Nested, Local, and Anonymous Classes 5.3 Defensive Programming, Immutability Patterns, and Validation
7 Chapter 6: Generics, Collections & Arrays
6.1 Generic Classes, Interfaces, Methods, and Type Erasure 6.2 Bounded Type Parameters and Wildcards (PECS Rule) 6.3 Collections Framework: List, Set, Queue, and Deque APIs 6.4 The Map Interface, Sorting, Comparable, and Comparator 6.5 Arrays: Declaration, Initialization, Multidimensional Arrays, and the Arrays Utility Class
8 Chapter 7: Functional Programming & Lambda Expressions
7.1 Functional Interfaces and Lambda Syntax Rules 7.2 Standard Functional Interfaces in `java.util.function` 7.3 Method References: Static, Bound, Unbound, and Constructor References
9 Chapter 8: The Stream API
8.1 Stream Lifecycle: Creation, Pipeline Architecture, and Lazy Evaluation 8.2 Intermediate Stream Operations: Filtering, Mapping, Sorting, and Slicing 8.3 Terminal Stream Operations: Reduction, Matching, Finding, and Collecting 8.4 Primitive Streams (`IntStream`, `LongStream`, `DoubleStream`) and Numeric Statistics
10 Chapter 9: Advanced Streams & Collectors
9.1 The Optional Class: Safe Null Handling, Transformation, and Chaining 9.2 The Collectors API: Downstream Reductions, Grouping, and Partitioning 9.3 Parallel Streams: Fork/Join Pool, Spliterators, and Concurrency Pitfalls
11 Chapter 10: Exception Handling
10.1 The Java Exception Hierarchy: Checked vs. Unchecked Exceptions and Errors 10.2 Exception Constructs: `try-catch-finally`, Multi-Catch, and Rethrowing 10.3 Try-With-Resources, `AutoCloseable`, Suppressed Exceptions, and Custom Exceptions
12 Chapter 11: Date/Time API & Localization
11.1 Date and Time Core Types: `LocalDate`, `LocalTime`, `LocalDateTime` 11.2 Timestamps, Intervals, and Durations: `Instant`, `Period`, and `Duration` 11.3 Time Zones, Daylight Saving Time (DST) Offsets, and `ZonedDateTime` 11.4 Internationalization and Localization: `Locale`, `ResourceBundle`, and Formatters 11.5 Formatting and Parsing Messages, Numbers, Percentages, and Localized Dates
13 Chapter 12: Java Platform Module System (JPMS)
12.1 Module Architecture, `module-info.java`, and Module Paths 12.2 Module Directives: `requires`, `requires transitive`, `exports`, and Qualified Exports 12.3 Reflection, Deep Encapsulation, `opens`, and Open Modules 12.4 Services in JPMS (`uses`, `provides...with`), Migration Paths, and Tooling (`jlink`, `jdeps`) 12.5 Compiling and Packaging Code: Non-Modular JARs, Modular JARs, and Migration Strategies
14 Chapter 13: Concurrency & Multithreading
13.1 Thread Fundamentals, `Runnable`, `Callable`, and Thread Lifecycle 13.2 Memory Visibility, `volatile`, Intrinsic Locks, and Synchronization 13.3 The Concurrency Framework: `ExecutorService`, Thread Pools, and `Future` 13.4 Concurrent Collections, Atomic Variables, Explicit Locks, and `CompletableFuture`
15 Chapter 14: Java I/O and NIO.2
14.1 Classical I/O: Byte and Character Streams, Readers, Writers, and Buffering 14.2 Object Serialization, `Serializable`, `transient`, and `serialVersionUID` 14.3 NIO.2 Architecture: `Path`, `Paths`, and Basic `Files` Operations 14.4 Advanced NIO.2: Directory Walking, Streams (`Files.lines`, `walk`), and `WatchService`
16 Chapter 15: Accessing Databases with JDBC
15.1 JDBC Architecture, Drivers, `DriverManager`, and `DataSource` Connections 15.2 SQL Execution: `Statement`, `PreparedStatement`, and `CallableStatement` 15.3 `ResultSet` Navigation, Data Types, and Transaction Management (Commit, Rollback, Savepoints)
17 Chapter 16: Annotations & the Java Logging API
16.1 Standard Annotations: @Override, @FunctionalInterface, @Deprecated, @SuppressWarnings, and @SafeVarargs 16.2 Java Logging API Basics: Logger, Levels, Handlers, and Configuration
6.3 Collections Framework: List, Set, Queue, and Deque APIs
Key Takeaways Explain This Topic AI
The Collection interface forms the root of standard collection types, offering bulk operations, iterators, and predicate removals (removeIf); Map is an independent hierarchy.
List implementations maintain sequence and indexed access: ArrayList delivers O(1) random lookups backed by dynamic arrays, while LinkedList provides O(1) head/tail insertions via doubly-linked nodes.
Set implementations enforce uniqueness: HashSet provides O(1) hashing with one null allowed, LinkedHashSet preserves insertion order, and TreeSet enforces sorted ordering while strictly rejecting null elements.
Queue and Deque APIs distinguish exception-throwing methods (add, remove, element) from special-value methods (offer, poll, peek); ArrayDeque is the preferred null-rejecting implementation for both stacks and FIFO queues.
Immutable collection factories (List.of, Set.of) produce unmodifiable, null-hostile collections; in contrast, Arrays.asList creates a fixed-size, array-backed list that allows element replacements and permits null.
Last updated: October 2026
6.3 Collections Framework: List , Set , Queue , and Deque APIs
The Java Collections Framework (JCF) provides a unified architecture for managing groups of objects. Defined primarily in java.util , the framework separates abstract behavioral contracts (interfaces) from concrete data structure implementations. The 1Z0-829 examination tests deep familiarity with collection hierarchies, operation complexities, null handling nuances, queue/deque method dualities, and modern unmodifiable collection factories.
The Core Collection Hierarchy
The root interface for collections is java.lang.Iterable<T> , which enables the enhanced for loop. java.util.Collection<E> extends Iterable<E> and defines fundamental bulk and element operations inherited by List , Set , and Queue . Iterable<E>
- │
- Collection<E>
- ┌──────┼──────┐
- │ │ │
- List<E> Set<E> Queue<E>
- │ │ │
- │ NavigableSet Deque<E>
Note
Map<K, V> does not extend Collection . Maps represent key-value associations and define an independent hierarchy, although they expose collection views via keySet() , values() , and entrySet() .
Core Collection methods include:
add(E e) , addAll(Collection<? extends E> c) : Inserts elements.
remove(Object o) , removeAll(Collection<?> c) : Removes matching elements.
removeIf(Predicate<? super E> filter) : Removes all elements matching the given predicate in place (introduced in Java 8).
retainAll(Collection<?> c) : Retains only elements contained in the specified collection (intersection).
contains(Object o) , containsAll(Collection<?> c) : Membership tests.
size() , isEmpty() , clear() , toArray() : Structural queries and conversions.
The List Interface and Implementations
A List<E> is an ordered collection (sequence) that allows duplicate elements and precise positional access via zero-based integer indices ( get(int) , set(int, E) , add(int, E) , remove(int) ).
ArrayList vs. LinkedList
- Feature ArrayList<E> LinkedList<E>
- Underlying Structure Resizable array ( Object[] ) Doubly-linked nodes ( Node<E> )
- Positional Access ( get / set ) O ( 1 ) O(1) O ( 1 ) constant time O ( n ) O(n) O ( n ) linear traversal
- Append ( add ) Amortized O ( 1 ) O(1) O ( 1 ) O ( 1 ) O(1) O ( 1 ) constant time
Arbitrary Insert/Delete O ( n ) O(n) O ( n ) due to System.arraycopy shift O ( 1 ) O(1) O ( 1 ) once node is reached, but O ( n ) O(n) O ( n ) to locate index
- Memory Footprint Compact contiguous memory High per-element overhead (prev/next pointers)
- Interface Contracts List , RandomAccess , Cloneable List , Deque , Queue , Cloneable
- The List<Integer>.remove() Overload Trap
A primary exam pitfall involves method overloading between remove(int index) and remove(Object o) on integer lists: List<Integer> numbers = new ArrayList<>(List.of(10, 20, 30));
- // Invokes remove(int index): removes element at index 1 (value 20)
- numbers.remove(1);
- System.out.println(numbers); // Prints [10, 30]
- // Invokes remove(Object o): removes the value 10
- numbers.remove(Integer.valueOf(10));
- System.out.println(numbers); // Prints [30]
// Attempting numbers.remove(30) treats 30 as an INDEX!
// numbers.remove(30); // Throws IndexOutOfBoundsException at runtime!
The Set Interface and Implementations
A Set<E> represents an unordered collection that prohibits duplicate elements. If an element e is already present (where existing.equals(e) is true ), calling add(e) returns false and leaves the set unmodified.
Comparison of Core Set Implementations
Implementation Ordering Guarantee Null Policy Underlying Data Structure Access Time
HashSet No guaranteed order; can change on rehash Allows one null Hash table ( HashMap ) O ( 1 ) O(1) O ( 1 ) lookup/add
LinkedHashSet Preserves element insertion order Allows one null Hash table + doubly-linked list O ( 1 ) O(1) O ( 1 ) lookup/add
TreeSet Sorted order (natural Comparable or Comparator ) Strictly rejects null Red-Black tree ( TreeMap ) O ( log n ) O(\log n) O ( lo g n ) lookup/add
Warning
The TreeSet NullPointerException Trap Attempting to insert null into a TreeSet using natural ordering throws a NullPointerException immediately—even if the TreeSet is completely empty! Because TreeSet must compare elements via compareTo() , attempting to invoke a comparison on null triggers an exception.
NavigableSet Navigation Methods
TreeSet implements NavigableSet<E> (which extends SortedSet<E> ), offering rich directional search methods:
lower(e) : Greatest element strictly less than e ( < e ), or null .
floor(e) : Greatest element less than or equal to e ( <= e ), or null .
ceiling(e) : Least element greater than or equal to e ( >= e ), or null .
higher(e) : Least element strictly greater than e ( > e ), or null .
pollFirst() , pollLast() : Retrieves and removes the lowest or highest element, or returns null if empty.
descendingSet() : Returns a reverse-order view of the set. NavigableSet<Integer> set = new TreeSet<>(List.of(10, 20, 30, 40));
- System.out.println(set.lower(20)); // 10 (strictly < 20)
- System.out.println(set.floor(20)); // 20 (<= 20)
- System.out.println(set.ceiling(25)); // 30 (>= 25)
- System.out.println(set.higher(30)); // 40 (strictly > 30)
- The Queue and Deque Interfaces
Queues model collections designed for holding elements prior to processing. Queue<E> handles First-In, First-Out (FIFO) ordering, while Deque<E> (Double-Ended Queue) supports insertion and removal at both ends, serving as both a FIFO queue and a Last-In, First-Out (LIFO) stack.
Method Dualities: Exception vs. Special Value
Queue operations are structured into two distinct sets of methods based on failure handling:
- Operation Type Throws Exception on Failure Returns Special Value ( false or null )
- Insert add(e) (throws IllegalStateException if full) offer(e) (returns false if full)
- Remove remove() (throws NoSuchElementException if empty) poll() (returns null if empty)
- Examine element() (throws NoSuchElementException if empty) peek() (returns null if empty)
- Deque Operations and Stack Methods
Deque expands these dualities to both the head and tail:
Head Operations : addFirst , offerFirst , removeFirst , pollFirst , getFirst , peekFirst .
Tail Operations : addLast , offerLast , removeLast , pollLast , getLast , peekLast .
Stack Methods (LIFO) :
push(e) : Equivalent to addFirst(e) (inserts at head; throws exception if capacity reached).
pop() : Equivalent to removeFirst() (removes from head; throws NoSuchElementException if empty).
peek() : Equivalent to peekFirst() (inspects head; returns null if empty).
ArrayDeque as Preferred Stack and Queue
ArrayDeque is the industry-standard implementation of Deque backed by a circular array. It is significantly faster and more cache-efficient than LinkedList or legacy java.util.Stack (which is synchronized and extends Vector ).
Warning
ArrayDeque Strictly Rejects null Unlike LinkedList , ArrayDeque does not permit null elements . Invoking deque.add(null) , deque.push(null) , or deque.offer(null) immediately throws a NullPointerException . This constraint exists because methods like poll() and peek() rely on null as a sentinel value indicating that the deque is empty.
Unmodifiable Collection Factories vs. Arrays.asList
Java 9 introduced static factory methods ( List.of() , Set.of() ) that produce unmodifiable collection instances. Understanding the operational differences between these factories, List.copyOf() , and Arrays.asList() is vital for the exam. // 1. Arrays.asList: Fixed-size, backed by underlying array
- String[] arr = { "A", "B" };
- List<String> backedList = Arrays.asList(arr);
- backedList.set(0, "Z"); // Allowed! Updates array: arr[0] becomes "Z"
- // backedList.add("C"); // Throws UnsupportedOperationException (cannot change size)
- // 2. List.of: Truly immutable instance
- List<String> immutableList = List.of("A", "B");
- // immutableList.set(0, "Z"); // Throws UnsupportedOperationException
- // List.of("A", null); // Throws NullPointerException (nulls forbidden!)
- // 3. Set.of: Truly immutable set (rejects duplicates and nulls)
- // Set.of("A", "A"); // Throws IllegalArgumentException (duplicate elements!)
- // Set.of("A", null); // Throws NullPointerException
- // 4. List.copyOf: Unmodifiable defensive copy
- List<String> copy = List.copyOf(backedList);
// If source contains null, List.copyOf throws NullPointerException!
Summary Comparison of Collection Creation Methods
- Characteristic List.of(...) Arrays.asList(...) new ArrayList<>(...)
- Mutability Completely immutable Fixed-size (in-place replacement allowed) Fully mutable (resizeable)
- Null Support Rejects null ( NullPointerException ) Allows null Allows null
- Backing Store Internal optimized class Directly backed by source array Independent heap array
Structural Modifications Throws UnsupportedOperationException Throws UnsupportedOperationException Permitted ( add , remove )