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.

💻 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:

Example 1: add, get, set, size
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));
    }
}
Running…

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:

Example 2: add(index, value) inserts, not replaces
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());
    }
}
Running…

[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:

Example 3: remove(index) removes by position
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());
    }
}
Running…

[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.

1
⚠ Using array syntax arr[i] instead of list.get(i)

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
2
⚠ Forgetting the import statement

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.*;

3
⚠ Confusing remove(int index) with remove(Object obj)

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.

ArrayList list = ...;
list.remove(1);                 // removes at index 1
list.remove(Integer.valueOf(1)); // removes value 1
4
⚠ Thinking size() and length behave the same as arrays

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)
🎓 AP Exam Tip

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.

⚠ Watch Out!

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)

Your Score: 0 / 0
1. What does list.get(0) return for ArrayList containing ["a","b","c"]?
2. What is the size of the list after these operations?
ArrayList L = new ArrayList<>();
L.add(1); L.add(2); L.add(3); L.remove(0);
3. What does list.remove(2) do to [10, 20, 30, 40]?
4. What is the correct syntax to access element at index 3 in an ArrayList named list?
5. What is the result of list.add(1, "X") applied to ["A","B","C"]?
6. Which is the correct way to get the size of an ArrayList named items?
7. After list.set(2, 99) applied to [10, 20, 30, 40], what is the list?
8. What import is required to use ArrayList in Java?

❓ Frequently Asked Questions

What is an ArrayList in AP CSA?

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.

What is the difference between ArrayList and array in AP CSA?

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.

What does ArrayList remove(int index) do?

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, remove(1) removes at index 1, NOT the value 1.

What is autoboxing in AP CSA?

Autoboxing is Java's automatic conversion between primitive types (int, double) and their wrapper classes (Integer, Double). ArrayList stores Integer objects, but you can add int values because Java automatically boxes them.

What is the difference between add(val) and add(index, val)?

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.

TC

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

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.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

tanner@apcsexamprep.com

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at tanner@apcsexamprep.com