Home

Tutoring

Subjects

Live Classes

Study Coach

Essay Review

On-Demand Courses

Colleges

Games

Opening subject page...

Loading your content

AP Computer Science a

Arrays and ArrayLists

Learn Arrays and ArrayLists in AP Computer Science a from the production AIPH study guide.

Study guide topics

Variables and Data TypesControl StructuresClasses and ObjectsInheritance and PolymorphismArrays and ArrayListsAlgorithm Analysis and SortingBuilding a Simple Banking AppManaging School RecordsDesigning a Quiz ProgramReading and Understanding CodeTime Management on the Exam

Advanced Topics

In a nutshell: Arrays and ArrayLists store multiple values efficiently.

## Storing Many Values Sometimes you need to keep track of lots of data—like scores, names, or objects. Arrays and ArrayLists are perfect for this. ### Arrays Arrays store a fixed number of elements of the same type. ```java int[] scores = {90, 85, 72, 100}; String[] names = new String[3]; ``` - Access elements with an index: `scores[0]` is 90. ### ArrayLists ArrayLists are flexible—they can grow and shrink as needed. ```java ArrayList<String> friends = new ArrayList<String>(); friends.add("Sam"); friends.add("Alex"); ``` - Use `.get(index)` to access elements: `friends.get(0)`. ## Choosing Between Them - Use arrays when the number of items is fixed. - Use ArrayLists for dynamic lists. ## Real-Life Example Arrays are like a row of lockers; ArrayLists are more like a backpack where you can add or remove things.

Examples

  • Storing the top 10 high scores in an `int[]` array.
  • Managing a dynamic list of online players with an `ArrayList<String>`.
PreviousNext