Java Tutorial · Chapter 11 of 12
Java Arrays
Store lists with indexes.
int[] scores = {90, 85, 88}; creates an array.
Use scores.length in loops instead of hard-coding size when possible.
Array sample
Try it Yourself »
public class Main {
public static void main(String[] args) {
int[] scores = {90, 85, 88, 92, 95};
for (int i = 0; i < scores.length; i++) {
System.out.println("Score " + (i + 1) + ": " + scores[i]);
}
}
}
Classroom Tips
- Indexes start at 0.
- Continue to OOP after arrays feel comfortable.