ArrayList Basics in AP CSA: Complete Guide (2025-2026)
ArrayList Basics in AP CSA: Complete Guide (2025-2026)
ArrayList in AP CSA is the most important data structure in Unit 4 (30–40% of the exam), and it is tested on every single AP Computer Science A exam. Unlike a regular array, an ArrayList can grow and shrink dynamically — you don't need to specify a size when you create it. An ArrayList stores objects (not primitives directly), uses autoboxing for int values, and provides methods like add(), remove(), get(), set(), and size() that appear constantly in both MCQ and FRQ questions.
📄 Table of Contents
💻 Code Examples — Predict First
Before running each example, write down your prediction. This is the single most effective AP exam study technique.
🤔 Predict the output before running:
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList nums = new ArrayList();
nums.add(10);
nums.add(20);
nums.add(30);
System.out.println(nums.size());
System.out.println(nums.get(1));
nums.set(0, 99);
System.out.println(nums.get(0));
}
}
3 / 20 / 99 — size() returns 3. get(1) returns the element at index 1 (20). set(0,99) replaces the element at index 0 with 99.
🤔 Predict the output before running:
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList words = new ArrayList();
words.add("apple");
words.add("banana");
words.add(1, "cherry"); // Insert at index 1
System.out.println(words);
System.out.println(words.size());
}
}
[apple, cherry, banana] / 3 — add(1, "cherry") INSERTS at index 1, shifting "banana" to index 2. Size becomes 3. This is different from set() which replaces.
🤔 Predict the output before running:
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add(5);
list.add(3);
list.add(8);
list.remove(1); // removes element at INDEX 1 (value 3)
System.out.println(list);
System.out.println(list.size());
}
}
[5, 8] / 2 — remove(1) removes the element at INDEX 1 (value 3). Elements after it shift left. Size decreases to 2.
❌ Common Pitfalls
These are the mistakes students most often make on the AP CSA exam with ArrayList AP CSA. Study them carefully.
ArrayList elements are accessed with .get(i), NOT with [i]. Using bracket notation on an ArrayList is a compile error. Similarly, assignment uses .set(i, val), not list[i] = val.
list[2] // COMPILE ERROR for ArrayList list.get(2) // CORRECT
ArrayList requires import java.util.ArrayList; at the top of the file. On the AP exam, this import is usually provided, but in FRQs you write from scratch you must include it. The exam also accepts import java.util.*;
remove(1) removes the element at INDEX 1. remove(Integer.valueOf(1)) removes the first occurrence of the VALUE 1. For ArrayList, this distinction matters critically on the AP exam.
ArrayListlist = ...; list.remove(1); // removes at index 1 list.remove(Integer.valueOf(1)); // removes value 1
Arrays use .length (a field, no parentheses). ArrayList uses .size() (a method, with parentheses). Mixing these up causes a compile error.
arr.length // array (field, no parens) list.size() // ArrayList (method, with parens)
On the AP CSA exam, the most common ArrayList FRQ pattern is: loop through the list, check a condition on each element, and either add, remove, or modify elements. The remove-while-iterating trap is the #1 FRQ deduction for ArrayList questions.
add(val) appends to the END of the list. add(index, val) INSERTS at that position and shifts everything right. set(index, val) REPLACES at that position. These three behave completely differently and the AP exam tests all three.
✍ Check for Understanding (8 Questions)
list.get(0) return for ArrayList containing ["a","b","c"]?
ArrayList L = new ArrayList<>();
L.add(1); L.add(2); L.add(3); L.remove(0);
list.remove(2) do to [10, 20, 30, 40]?
list.add(1, "X") applied to ["A","B","C"]?
list.set(2, 99) applied to [10, 20, 30, 40], what is the list?
❓ Frequently Asked Questions
An ArrayList is a resizable array from the java.util package that can grow and shrink dynamically. It stores objects (not primitives), uses methods like add(), remove(), get(), set(), and size(), and is the most important data structure tested on the AP CSA exam.
Arrays have fixed length (set at creation), use bracket notation (arr[i]), and use .length. ArrayLists are dynamic (resize automatically), use method calls (list.get(i)), and use .size(). Arrays can hold primitives; ArrayLists hold objects only.
remove(int index) removes the element at the specified index and shifts all subsequent elements one position to the left. The size decreases by 1. For ArrayList
Autoboxing is Java's automatic conversion between primitive types (int, double) and their wrapper classes (Integer, Double). ArrayList
add(val) appends to the end of the list. add(index, val) inserts at the specified position and shifts all elements at that index and beyond one position to the right. The size increases by 1 in both cases.
Tanner Crow — AP CS Teacher & Tutor
11+ years teaching AP Computer Science at Blue Valley North High School (Overland Park, KS). Verified Wyzant tutor with 1,845+ hours, 451+ five-star reviews, and a 5.0 rating. His AP CSA students score 5s at more than double the national rate.
- 54.5% of students score 5 on AP CSA (national avg: 25.5%)
- 1,845+ verified tutoring hours • 5.0 rating
- Free 1-on-1 tutoring inquiry: Wyzant Profile
🔗 Related Topics
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
tanner@apcsexamprep.com
Courses
AP CSA, CSP, & Cybersecurity
Response Time
Within 24 hours
Prefer email? Reach me directly at tanner@apcsexamprep.com