1D Arrays

Lesson 7 of 20

One name, many values — create an array, fill its numbered cells, and loop through them without losing track.

The big picture

Many values, one name

An array is a row of typed cells under one name, numbered from 0 — visit any cell instantly by its index.

A row of boxes

An array stores many values of ONE type under a single name, numbered from 0.

Create with new

int[] scores = new int[5] makes 5 cells in one block — all starting at 0.

Index access

scores[0] reads the first cell; scores.length is how many cells exist.

Loop through it

for (int i = 0; i < scores.length; i++) visits every cell in order.