Module 7: Arrays and ArrayList
Array vs ArrayList
Choose between arrays and ArrayList based on whether the size is fixed, how often the data changes, and what operations you need.
Author
Java Learner Editorial Team
Reviewer
Technical review by Java Learner
Last reviewed
2026-04-16
Java version
Java 25 LTS
Learning goals
- Compare arrays and ArrayList clearly
- Choose the right structure for a beginner task
- Avoid using one structure for every problem
Arrays are simpler and fixed-size: They work well when the number of values is known from the start.
ArrayList is more flexible but slightly heavier: It is useful when items may be added or removed during the program.
Both still use indexes: The big difference is not index access, but whether the size can change.
Practical rule: Pick the structure that matches the real job instead of always choosing the newer one.
Runnable examples
An array fits a fixed number of quiz questions
String[] answers = new String[5];
System.out.println(answers.length);Expected output
5
An ArrayList fits a changing task list
import java.util.ArrayList;
ArrayList<String> tasks = new ArrayList<>();
tasks.add("Study");
tasks.add("Build");
System.out.println(tasks.size());Expected output
2
Mini exercise
Decide whether an array or an `ArrayList` is better for a weekly timetable and for a shopping list that changes often.
Summary
- Arrays are fixed-size and simple.
- `ArrayList` is resizable and flexible.
- Choose based on whether the data size changes.
Next step
The intermediate track later goes deeper into the wider collections framework, but arrays and `ArrayList` cover the most important beginner cases first.
Sources used