Notes / Java / Arrays

Arrays in Java — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Arrays Java arrays store multiple values of the same type in a fixed-size, indexed structure — but unlike C, Java arrays are objects, and Java performs automatic bounds checking at runtime..

Syntax

syntax
type[] arrayName = new type[size];
type[] arrayName = {value1, value2, ...};

Example

java
public class Main {
    public static void main(String[] args) {
        int[] scores = {90, 85, 70, 60, 95};
        for (int i = 0; i < scores.length; i++) {
            System.out.print(scores[i] + " ");
        }
    }
}

Output

output90 85 70 60 95

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Know the difference between array.length (a field, arrays) and list.size() (a method, ArrayList/collections) — a very common trip-up.
Back to notes Read full lesson →