Practical Coding in Java

Learn to write and validate your own code

Darren Kessner, PhD

(revised January 9, 2026)

Previous: Coding Exercises: Classes and Objects

5. Arrays

In this chapter we explore arrays, which allow you to store, modify, and retrieve large blocks of data.

In the examples you will see how to declare, initialize, and accesss arrays. You will also learn how to iterate through arrays using loops. And you will practice performing calculations on arrays.

Array objects

An array object represents a list of values of a given type.

int[] values = {1, 3, 5};

Arrays have a member variable length:

System.out.println(values.length); // "3"

Array Indexing

Java uses 0-based indexing for arrays (same as for Strings).

\[ \underset{0}{\fbox{ 1 }} \underset{1}{\fbox{ 3 }} \underset{2}{\fbox{ 5 }} \]


Next: