Day 1: ArrayList Mastery | AP CSA 7-Day Cram Kit
DAY 1 Â |Â ArrayList Mastery
Unit 4  | 30–40% of exam  | FRQ 3 is ALWAYS ArrayList
Your Plan for Today
Read the concept summary below.
apcsexamprep.com/pages/ap-csa-unit-4-data-collections-study-guide
Focus: ArrayList basics, add/remove, traversal patterns.
Go to the Test Builder. Set filter: Unit 4 → ArrayList.
apcsexamprep.com/pages/ap-csa-test-builder
Do 10 questions. 2 minutes max per question.
-> Score 8-10 correct: solid. Move to Step 3.
-> Score 5-7 correct: reread the remove-while-iterating section, then do Step 3.
-> Score 0-4 correct: stop. Reread the full ArrayList section. Redo 10 questions before Step 3.
Write the full solution on paper BEFORE checking the answer.
Use: 2024 AP CSA Free Response Question 3 (WordChecker — ArrayList of Strings)
apcsexamprep.com/pages/ap-csa-2024-frq-3-solution-wordchecker-arraylist-strings
Write your full answer on paper or in Bluebook before checking the solution.
Solution: apcsexamprep.com/pages/ap-csa-2024-frq-3-solution-wordchecker-arraylist-strings
| Your Score | What to Do |
|---|---|
| 0–3 pts | Do NOT move on. Reread the concept summary, then attempt 2023 FRQ 3 tomorrow. |
| 4–6 pts | Decent. Review what you missed on the rubric, then move to Day 2. |
| 7–9 pts | Strong. Scan the rubric for any points lost, then move to Day 2. |
Concept Review
-
ArrayList— declare and createlist = new ArrayList (); -
list.add(value)— adds to the end -
list.add(index, value)— inserts at that position, shifts everything right -
list.get(index)— returns the element (use this, NOTlist[index]) -
list.set(index, value)— replaces the element at that index -
list.remove(index)— removes by POSITION, shifts everything left -
list.size()— number of elements currently in the list -
ArrayListuses Integer (capital I), not int — Java handles the conversion
Critical Pattern: Removing While Iterating
If you remove an element and do NOT adjust the index, you skip the next element.
// WRONG -- skips elements after each removal
for (int i = 0; i < list.size(); i++)
{
if (list.get(i) < 0)
{
list.remove(i); // BUG: i now points to what was i+1
}
}
// CORRECT -- decrement i after removal
for (int i = 0; i < list.size(); i++)
{
if (list.get(i) < 0)
{
list.remove(i);
i--; // step back so we don't skip the next element
}
}
// CORRECT -- iterate backward
for (int i = list.size() - 1; i >= 0; i--)
{
if (list.get(i) < 0)
{
list.remove(i); // safe: removal only shifts what is AHEAD of i
}
}
- ArrayList: dynamic size, grows/shrinks  | Array: fixed size set at creation
-
list.get(i)andlist.size()Â |Âarr[i]andarr.length(no parentheses) -
ArrayListNOTArrayList— must use wrapper type - FRQ 3 will always use ArrayList — you will never use arrays for FRQ 3
-
list.remove(2)removes the element at INDEX 2, not the VALUE 2 — common trap
Practice Questions
public static void removeNegatives(ArrayListdata) { for (int i = 0; i < data.size(); i++) { if (data.get(i) < 0) { data.remove(i); } } }
- (A) The condition < 0 should be <= 0
- (B) The loop removes elements correctly as written
- (C) After removing an element, i is not decremented, so the next element is skipped
- (D) list.remove() does not work on an ArrayList of integers
â–¶ REVEAL ANSWER
Answer: C
When you call list.remove(i), the element at i is deleted and everything after it shifts left. The element that was at i+1 is now at i. The loop then does i++ and skips it. Fix: add i-- after the remove call, or iterate backward.
I. An ArrayList automatically grows when elements are added.
II. list.remove(2) always removes the Integer value 2 from an ArrayList
III. An ArrayList
- (A) I only
- (B) I and III only
- (C) II and III only
- (D) I, II, and III
â–¶ REVEAL ANSWER
Answer: B
I is TRUE. II is FALSE -- remove(2) removes the element at INDEX 2, not the value 2. III is TRUE. Only I and III are correct.
public static int findMax(ArrayListlist) { int max = list.get(0); for (int i = 1; i < list.size(); i++) { if (list.get(i) > max) { max = list.get(i); } } return max; }
- (A) 3
- (B) 5
- (C) 14
- (D) 1
â–¶ REVEAL ANSWER
Answer: B
The method tracks the largest value seen. Starting with max = 3, it updates: stays 3, stays 3, updates to 4, updates to 5. Returns 5.
// Line 1 public static ArrayListgetEvens(ArrayList nums) { ArrayList result = new ArrayList (); // Line 4 for (int i = 0; i < nums.size() - 1; i++) { // Line 5 if (nums.get(i) % 2 == 0) { // Line 7 result.add(nums.get(i)); } } return result; }
- (A) Line 1 -- wrong return type
- (B) Line 4 -- the loop condition stops one element too early
- (C) Line 5 -- wrong condition for detecting even numbers
- (D) Line 7 -- adds to the wrong list
â–¶ REVEAL ANSWER
Answer: B
Line 4 uses i < nums.size() - 1, which stops at index size-2. The last element is never checked. The correct condition is i < nums.size().
list.add(2, 30); list.remove(1); list.set(2, 20);
- (A) [10, 30, 20, 40]
- (B) [10, 30, 40]
- (C) [10, 30, 30, 40]
- (D) [10, 20, 30, 40]
â–¶ REVEAL ANSWER
Answer: A
add(2, 30) -> [10, 20, 30, 30, 40]. remove(1) removes index 1 (value 20) -> [10, 30, 30, 40]. set(2, 20) replaces index 2 with 20 -> [10, 30, 20, 40].
Answer Key (for printing)
Q1: C Â Â Q2: B Â Â Q3: B Â Â Q4: B Â Â Q5: A
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.
Prefer email? Reach me directly at [email protected]