Skip to content

Chapter 7 of 37

Arrays

Work with fixed-size one-dimensional, multidimensional, and ragged arrays.

32 minutes 10 quick checksBy Subha Prasad
Lesson 7 of 37Course navigation

Lesson content

Read, practise, then check your understanding

An array is a fixed-length object with zero-based indices. Its element type is fixed, primitive elements receive zero-like defaults, and reference elements begin as null. Invalid indices throw ArrayIndexOutOfBoundsException.

Shapes and utilities

int[] scores = {72, 84, 91};
int[][] matrix = {
    {1, 2, 3},
    {4, 5, 6}
};
int[][] ragged = new int[3][];
ragged[0] = new int[2];

Arrays.sort(scores);
int position = Arrays.binarySearch(scores, 84);

Java multidimensional arrays are arrays of arrays, so rows can differ in length and are separate objects. Array covariance permits Number[] values = new Integer[2], but an invalid store fails at runtime; generic collections provide stronger compile-time safety. Use Arrays.copyOf, fill, equals, deepEquals, and stream rather than rewriting standard operations. Choose ArrayList when size must change and clone nested arrays explicitly when a deep copy is required.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes array?
Which Java term matches this description: A fixed-length object storing same-type elements by zero-based index.
Which statement best describes length field?
Which Java term matches this description: The final array field reporting its element count.
Which statement best describes multidimensional array?
Which Java term matches this description: An array whose elements are themselves arrays.
Which statement best describes ragged array?
Which Java term matches this description: A nested array whose rows may have different lengths.
Which statement best describes Arrays utility?
Which Java term matches this description: The java.util helper providing sort, fill, compare, and search operations.

0 of 10 checks passed

Your progress is saved on this device.