AP Computer Science A Unit 4: Data Collections
Unit 4 is the single heaviest unit on the exam — and it's the basis for two of the four free-response questions. If you master one unit, make it this one.
Data Collections accounts for roughly 30–40% of the multiple-choice questions — more than any other unit — and it directly drives the ArrayList and 2D array free-response questions. Together with Unit 2 (Selection & Iteration), it makes up the largest share of the exam.
What's in Unit 4
- 1D arrays — fixed-size collections of one type
- ArrayList — a resizable list of objects
- 2D arrays — grids of rows and columns
- Traversals — visiting elements with loops
- Standard algorithms — searching and sorting that operate on these structures
Arrays — the foundation
- An array holds multiple values of the same type (primitives or object references).
- Its length is fixed at creation and cannot change.
- Created with
new, elements start at defaults:int→ 0,double→ 0.0,boolean→ false, objects →null. - An initializer list creates and fills in one step:
int[] nums = {1, 2, 3}; - Valid indices run from
0tolength - 1. Going outside that throws anArrayIndexOutOfBoundsException. - Traverse with a standard
forloop (when you need the index) or an enhancedfor-eachloop (when you just need the values).
ArrayList — when the size can change
- Unlike an array, an
ArrayListgrows and shrinks as you add and remove. - Core methods:
add,get,set,remove,size(andaddat a specific index). - It stores objects, so use wrapper classes —
Integer,Double— for primitive values.
2D arrays
- A 2D array is a grid; you access an element with
arr[row][col]. - Row-major traversal: an outer loop over the rows, an inner loop over the columns.
arr.lengthis the number of rows;arr[r].lengthis the number of columns in rowr.
Standard algorithms to recognize
- Linear search — check each element in order until you find the target; works on any data.
- Binary search — repeatedly check the middle of a sorted array and eliminate half each time.
- Selection, insertion, and merge sort — know how each one orders data. Merge sort is the most efficient of the three.
Mistakes that cost the most points
- Off-by-one errors and reading past the end of an array.
- Using
==instead of.equals()to compare objects such asStrings. - Forgetting that an array's length is fixed (you can't
addto an array — that's whatArrayListis for). - Modifying an
ArrayListwhile iterating forward over it.
Practice the Unit 4 free-response style
Write a method on an array or ArrayList and get it graded against a rubric — instant feedback on your loop bounds, edge cases, and return value. No account needed.
How this maps to the exam
Free-response question 3 asks you to work with an ArrayList, and question 4 asks you to traverse and manipulate a 2D array. Both reward correct loop bounds and clean traversal — exactly the Unit 4 skills above. Practicing these two question types is the most direct way to turn Unit 4 study into points.
The 2025–26 redesign consolidated the course into four units and removed inheritance, polymorphism, extends, and super from the required content, while adding File and Scanner for reading text files. Exam weighting and content can change — always confirm current details on the official College Board AP Central page. Silver is an independent study tool and is not affiliated with or endorsed by the College Board.