Study guide
6.5 Arrays: Declaration, Initialization, Multidimensional Arrays, and the Arrays Utility Class
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.5 Arrays: Declaration, Initialization, Multidimensional Arrays, and the Arrays Utility Class
Key Takeaways Explain This Topic AI
In the declaration int c[], d; only c is an array and d is a plain int, while int[] a, b; declares two arrays.
Array elements default to 0, false, '\u0000' , or null, and length is a field rather than a method.
Arrays.binarySearch on a sorted array returns the index or -(insertion point) - 1, and its result is undefined for unsorted input.
Arrays.mismatch returns the first differing index or -1, while Arrays.compare orders arrays element by element with shorter prefixes first.
Arrays do not override equals or toString, so use Arrays.equals, Arrays.toString, and Arrays.deepToString to compare and print contents.
Last updated: October 2026
6.5 Arrays: Declaration, Initialization, Multidimensional Arrays, and the Arrays Utility Class
The collections objective begins with "Create Java arrays", and arrays also sit underneath varargs, main(String[] args) , and Stream.toArray . Array questions test declaration syntax, default values, exceptions, and the exact return values of the java.util.Arrays helper methods.
Declaring and Creating Arrays
An array is an object with a fixed length that holds elements of one type. The brackets may follow the type or the variable name, and that choice changes multi-variable declarations: int[] a, b; // a and b are both int[]
int c[], d; // c is int[], but d is a plain int!
int[] e, f[]; // e is int[], f is int[][]
Creation rules:
- Code Result
- int[] nums = new int[3]; Three elements, each 0
- int[] nums = new int[] {1, 2, 3}; Size inferred from the initializer
- int[] nums = {1, 2, 3}; Shorthand, allowed only in a declaration
- int[] bad = new int[3] {1, 2, 3}; Compile error: size and initializer together
- int[] none = new int[0]; Legal empty array ( length is 0 )
- int[] neg = new int[-1]; Compiles, throws NegativeArraySizeException at runtime
Elements receive the same defaults as fields: 0 for numeric types, false for boolean , '\u0000' for char , and null for references. Arrays.toString(new String[2]) prints [null, null] .
length is a field ( nums.length ), while String uses the method length() .
Valid indexes run from 0 to length - 1 ; anything else throws ArrayIndexOutOfBoundsException at runtime.
An array reference prints like [I@1b6d3586 because arrays do not override toString() ; use Arrays.toString(arr) .
Arrays do not override equals() either: new int[] {1}.equals(new int[] {1}) is false , while Arrays.equals(...) compares contents and returns true .
Multidimensional and Jagged Arrays
Java has arrays of arrays. Each row is its own array object, so rows can have different lengths: int[][] grid = new int[2][3]; // 2 rows, each an int[3] of zeros
- int[][] jagged = {{1}, {2, 3}, {}}; // row lengths 1, 2, and 0
- int[][] partial = new int[3][]; // rows not created yet
- System.out.println(grid.length); // 2 (number of rows)
- System.out.println(grid[0].length); // 3
- System.out.println(partial[0]); // null
- System.out.println(Arrays.deepToString(jagged)); // [[1], [2, 3], []]
- // int[][] wrong = new int[][3]; // Compile error: the first dimension is required
Use nested loops (or for (int[] row : grid) ) to traverse rows and columns, and Arrays.deepToString to print nested arrays.
The java.util.Arrays Utility Class
- Method Example Result
- sort(arr) String[] s = {"b", "A", "a", "10", "9"}; [10, 9, A, a, b] (digits before uppercase before lowercase)
sort(arr, comparator) Arrays.sort(boxed, Comparator.reverseOrder()) Works only on object arrays such as Integer[] , not int[]
- binarySearch(arr, key) binarySearch(new int[] {2, 4, 6, 8}, 6) 2 (the index)
- binarySearch (key absent) binarySearch(new int[] {2, 4, 6, 8}, 5) -3 , computed as -(insertion point) - 1
- equals(a, b) equals(new int[] {1}, new int[] {1}) true
compare(a, b) compare(new int[] {1, 2}, new int[] {1, 2, 3}) Negative: equal prefix, so the shorter array is smaller
- mismatch(a, b) mismatch(new int[] {1, 2, 3}, new int[] {1, 2, 4}) 2 (first differing index), or -1 if equal
- fill(arr, v) fill(new int[3], 7) [7, 7, 7]
- copyOf(arr, n) copyOf(new int[] {1, 2, 3}, 5) [1, 2, 3, 0, 0] (pads or truncates)
- copyOfRange(arr, from, to) copyOfRange(new int[] {1, 2, 3, 4}, 1, 3) [2, 3] (end exclusive)
- asList(...) Arrays.asList("x", "y") Fixed-size list backed by the array (see 6.3)
- stream(arr) Arrays.stream(new int[] {1, 2}) An IntStream (see 8.1)
Warning
binarySearch requires a sorted array. On an unsorted array the result is undefined, so exam answers such as "the result cannot be predicted" are correct for unsorted input. For a missing key, compute the insertion point first: in {2, 4, 6, 8} , the key 5 belongs at index 2 , so the result is -(2) - 1 = -3 ; the key 1 gives -1 , and the key 9 gives -5 .
compare versus mismatch
Arrays.compare returns an int like compareTo : it compares elements in order, and if one array is a prefix of the other, the shorter array is smaller. Arrays.compare(new int[] {1, 3}, new int[] {1, 2, 9}) is positive because 3 > 2 at index 1, even though the first array is shorter. Arrays.mismatch instead returns the first index where the arrays differ: mismatch(new int[] {1, 2}, new int[] {1, 2, 3}) is 2 (the length of the shorter array), and identical arrays give -1 .
Arrays, Varargs, and Covariance
A varargs parameter ( String... names ) is an array inside the method, and callers may pass an existing array (see 3.1).
Arrays are covariant : a String[] can be assigned to an Object[] variable, but storing an Integer into it throws ArrayStoreException at runtime (see 6.2).
arr.clone() creates a new array with the same elements; for arrays of objects, the elements themselves are shared (a shallow copy).