Advanced Placement Computer Science A focusing on Java programming and object-oriented design.
Sometimes you need to keep track of lots of data—like scores, names, or objects. Arrays and ArrayLists are perfect for this.
Arrays store a fixed number of elements of the same type.
int[] scores = {90, 85, 72, 100};
String[] names = new String[3];
scores[0]
is 90.ArrayLists are flexible—they can grow and shrink as needed.
ArrayList<String> friends = new ArrayList<String>();
friends.add("Sam");
friends.add("Alex");
.get(index)
to access elements: friends.get(0)
.Arrays are like a row of lockers; ArrayLists are more like a backpack where you can add or remove things.
Storing the top 10 high scores in an int[]
array.
Managing a dynamic list of online players with an ArrayList<String>
.
Arrays and ArrayLists store multiple values efficiently.