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

STEP 1Review Concepts (15 min)

Read the concept summary below.

apcsexamprep.com/pages/ap-csa-unit-4-data-collections-study-guide

Focus: ArrayList basics, add/remove, traversal patterns.

STEP 2MCQ Practice (25 min)

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.

STEP 3FRQ Practice (35 min)

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

FRQ Task: 2024 AP CSA Free Response Question 3

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 Essentials
  • ArrayList list = new ArrayList(); — declare and create
  • 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, NOT list[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
  • ArrayList uses 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 vs Array
  • ArrayList: dynamic size, grows/shrinks  |  Array: fixed size set at creation
  • list.get(i) and list.size()  |  arr[i] and arr.length (no parentheses)
  • ArrayList NOT ArrayList — 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

Q1.  [SPOT THE ERROR]
The method below is supposed to remove all negative numbers from an ArrayList named data. What is wrong with it?
public static void removeNegatives(ArrayList data)
{
   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.

Q2.  [I/II/III]
Which of the following statements about ArrayList are TRUE?
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 can store null as a valid element.
  • (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.

Q3.  [TRACE]
What does the method below return when called with a list containing [3, 1, 4, 1, 5]?
public static int findMax(ArrayList list)
{
   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.

Q4.  [SPOT THE ERROR]
The method below should return only the even numbers from the input list. Which line has the bug?
// Line 1
public static ArrayList getEvens(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().

Q5.  [TRACE]
An ArrayList starts as [10, 20, 30, 40]. After these three operations, what does it contain?
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.

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

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]