Lesson 1 of 516 minModule progress 0%

Module 7: Arrays and ArrayList

Arrays Basics

Use arrays to store a fixed-size group of values of the same type.

Author

Java Learner Editorial Team

Reviewer

Technical review by Java Learner

Last reviewed

2026-04-16

Java version

Java 25 LTS

How this lesson was prepared: AI-assisted draft, edited by hand, and checked against current Java 25 documentation and runnable examples.

Learning goals

  • Declare and create arrays
  • Read and update values by index
  • Understand that array size is fixed after creation

An array stores several values of the same type in one structure: It is one of the first tools for handling grouped data in Java.

Arrays have a fixed size: Once created, the length does not change.

Each value has an index starting at 0: That means the first item is at index 0, not index 1.

Why this matters: Arrays are simple, fast, and a strong way to learn indexed data before moving to resizable collections.

Runnable examples

Create and read an array

public class Main {
    public static void main(String[] args) {
        int[] scores = {90, 85, 70};
        System.out.println(scores[0]);
        scores[2] = 75;
        System.out.println(scores[2]);
    }
}

Expected output

90
75

Common mistakes

Trying to read an index outside the array length

Only use indexes from 0 up to `length - 1`.

Mini exercise

Create an array of four favorite foods and print the second one.

Summary

  • Arrays store same-type values in a fixed-size structure.
  • Indexes start at 0.
  • Array length cannot change after creation.

Next step

Next, loop through arrays instead of reading values one by one manually.

Sources used

Advertisement

Lesson check

If an array has length 5, what is its last valid index?

Next lesson →