SAT / PSAT
SAT / PSAT Prep
History & Social Science
AP World History AP US History AP European History AP Human Geography AP US Government & Politics AP Psychology AP Macroeconomics AP Microeconomics
English
AP English Language & Composition AP English Literature & Composition
Math & Computer Science
AP Calculus AB/BC AP Precalculus AP Statistics AP Computer Science A AP Computer Science Principles
Sciences
AP Biology AP Chemistry AP Environmental Science AP Physics 1 AP Physics 2
World Languages & Arts
AP Spanish Language AP Art History AP Music Theory Start studying →
Unit 4 · Data Collections Flashcards Cheat Sheet Essentials Visual Review MC Practice FRQ Practice

AP Computer Science A Unit 4 Cheat Sheet

A one-page visual summary of Data Collections — every collection, traversal, algorithm, and exam trap you need, on a single screen.

← Back to Unit 4 hub

The basics

What it covers: Arrays, array traversals and algorithms, text files, wrapper classes, ArrayList, 2D arrays, searching, sorting, and recursion.

Exam weight: About 30–40% of the multiple-choice section — the largest unit — and central to the Data Analysis free-response question.

The big question: How do you store, traverse, search, and sort collections of data?

Computational thinking practices: Design Code, Develop Code, Analyze Code, Document Code, and Use Computers Responsibly.

Key topics at a glance

Arrays

Fixed-size, indexed by 0 to length−1. Size is arr.length (a field, no parentheses). Out-of-range access throws ArrayIndexOutOfBoundsException.

Array Traversals

Standard for (int i = 0; i < arr.length; i++) gives index access; the enhanced for (int x : arr) reads each element but can’t assign or remove.

ArrayList

Resizable list of objects. Methods: add, get(i), set(i,x), remove(i), size(). Uses .size(), not .length. Stores wrapper types (ArrayList<Integer>).

ArrayList Removal

remove(i) shifts elements left. Removing in a forward loop skips the next element — don’t always increment i, or loop backwards.

Wrapper Classes

Integer and Double box primitives as objects. Autoboxing/unboxing convert automatically between int/Integer and double/Double.

2D Arrays

A grid: matrix[row][col]. Rows = matrix.length, columns = matrix[0].length. Traverse with nested loops (row-major).

Searching

Sequential/linear: check each element (works unsorted, up to n). Binary: check the middle of a sorted array, halve each step — far faster.

Sorting & Recursion

Selection sort (swap in the smallest), insertion sort (insert into sorted region). Recursion = a method calling itself with a base case + recursive case; merge sort and recursive binary search.

The key terms and rules you must know

Key themes to remember

Common exam traps