Java Tutorial: Arrays
Java arrays — declaration, initialisation, traversal, multi-dimensional arrays, and the Arrays utility class.
One variable, many values
Arrays store multiple values of the same type under one name. In Java, arrays are fixed-size — you decide the length upfront. For dynamic sizing, you'll use `ArrayList` (Chapter 16).
Arrays are the foundation of almost all data processing — sorting, searching, statistics, matrix math.
What you'll learn in this Java arrays tutorial
This interactive Java tutorial has 7 hands-on exercises. Estimated time: 18 minutes.
- Declare and initialise arrays — Two ways to create an array:
- Loop over arrays — Two ways to iterate:
- Find min, max, sum — Calculate statistics by looping through the array manually.
- Arrays utility class — `java.util.Arrays` provides ready-made operations:
- ArrayIndexOutOfBoundsException — Access an index that doesn't exist and Java throws `ArrayIndexOutOfBoundsException`. It's one of the most common Java ru…
- 2D arrays — matrices — 2D arrays are arrays of arrays — perfect for grids, tables, and matrices:
- Build a grade analyser — Final challenge — no starter code.
Java Arrays concepts covered
- One variable, many values