Data Collections
What this unit covers
The topics below follow the published CS A course framework for Unit 4. This unit is worth 30–40% of the exam, so budget your time against that rather than against how long the unit takes to teach.
Lessons in this unit
- 1D Arrays13 min · 3 objectivesCreate arrays with a literal or with `new`, and access elements by index · Use `.length` to find the number of elements · Recall the default values that `new` gives array elements
- ArrayList15 min · 3 objectivesCreate an `ArrayList` and use `add`, `get`, `size`, and `remove` · Explain how `remove(index)` shifts the remaining elements · Predict results of retrieving elements after modifying the list
- 2D Arrays14 min · 3 objectivesCreate a 2D array and access an element with `[row][col]` · Find the number of rows and columns from the array’s length fields · Trace element access in a rectangular grid
- Traversals, Searching & Sorting15 min · 3 objectivesUse an enhanced for-each loop to traverse and accumulate over an array · Trace a linear search for the maximum value · Distinguish reading elements (for-each) from needing indices (standard for)
Formulas in Unit 4
What examiners penalize here
- An index runs from 0 to `length - 1`. To loop over every element, use `for (int i = 0; i < arr.length; i++)` — note the strict `<`, which stops correctly at the last valid index.
- When removing elements in a loop, remember each `remove(i)` shifts later elements left. Iterating forward with a normal index can skip elements — a very common FRQ trap.
- To traverse a full grid, use `for (int r = 0; r < m.length; r++)` outside and `for (int c = 0; c < m[0].length; c++)` inside. The outer loop walks rows, the inner walks columns.
- Seed a max/min search with `a[0]` and start the loop at index 1. Seeding with 0 can be wrong for arrays of all-negative numbers, and forgetting to update `max` leaves it stuck at the first value.
Practice CS A
Our practice bank is drawn from across the whole course rather than filtered to one unit, which is closer to how the exam asks anyway — it will not tell you which unit a question is testing.
Questions about this unit
How much of the AP Computer Science A exam is Unit 4?
Unit 4, Data Collections, is worth 30–40% of the CS A multiple-choice section according to the published course framework. Across all 4 units that makes it one of the heaviest units on the exam, and worth front-loading.
What topics are covered in CS A Unit 4?
Data Collections covers 1D arrays, ArrayList, 2D arrays and Traversals, searching & sorting.
How should I study CS A Unit 4?
Read the 4 lessons below first — about 55 minutes — then work practice questions on these topics. Finish with practice questions and read the explanation for every one you get right by elimination as well as the ones you miss.
All 4 units of AP Computer Science A
Unit names, topics and exam weights follow the published College Board course framework for AP Computer Science A. AP® is a trademark registered by the College Board, which does not endorse this site.