Exam prep

AP CSA Unit 4: collections are loops waiting to happen, and the bounds are the exam

Unit 4 hands you the containers: arrays fixed, ArrayLists growing, 2D arrays as rows of rows. It grades what you do across them, the accumulate, count, search and extreme patterns that the free response reuses every year. The traps live at the bounds and in indexes that shift when elements are removed.

DownloadApp StoreSoonGoogle Play
Free to startNo adsTR & EN

The tool below drills both from your notes.

WeSolve+ reads the whole document and writes the questions for you

Upload your PDF, photograph your notebook, or point the camera. WeSolve+ writes questions from that material, explains why each answer is right, reads the chapter back to you as a podcast, and remembers every item you missed until you own it.

Start free!

The tool below is a small browser-only tool and it is not WeSolve+: paste a few lines and text rules turn them into cards on the spot. The real app, the one that uses AI, is behind the link above.

Unit 4 collections, from your own notes

This is a browser-only tool, and that is all it isIt splits the text you paste by rule, and nothing else. WeSolve+ is a different thing entirely: it reads your whole PDF with AI, writes the reasoning behind every question, speaks the chapter back to you, and remembers what you missed so it can return it. Try the real app now, free!

This is a text splitter rather than a tutor. It turns pasted lines into cards by rule, and a gap in the paste is a gap in the deck.

Two containers, one habit of confusing their interfaces

An array has fixed length read as a field; an ArrayList grows, with size as a method and get, set, add and remove doing the work. The exam mixes the two syntaxes in one question deliberately, and the fix is mechanical: brackets and length for arrays, methods for lists, never crossed.

Four traversal patterns carry the unit, so name them as you write

Accumulate a total, count the matches, find the extreme, search for a target: nearly every collection question is one of these four wearing context. Each has a shape, initialise before the loop, update inside, conclude after, and the extreme pattern starts from the first element rather than zero, because an all negative array breaks the lazy version.

The enhanced for is convenient exactly until it is a trap

The enhanced for reads every element without index bookkeeping, which is why the exam likes it in disguise: it cannot assign into an array of primitives, and it cannot remove safely. When a question requires changing the collection, the indexed loop is the tool, and recognising which job the stem describes is the actual skill under test.

Removal shifts indexes, and the trap has one honest escape

Removing an element from an ArrayList slides everything after it one slot left, so a forward loop that removes then increments skips the neighbour. The reliable escapes: iterate backwards, or refuse to increment after a removal. The free response plants this trap most years, and naming the shift in a comment is how you show the grader you saw it.

2D arrays are rows of rows, and the loop order says which way you walk

A 2D array is an array whose elements are rows, so the outer loop walks rows and the inner walks columns, and swapping them walks the grid the other way. Row length comes from the row itself. Free response grids, image filters, seating charts, board games, are this section's patterns run twice, once per dimension.

What to photograph for Data Collections

Your traversal patterns and trap notes. Related: Unit 3, photo to quiz and pricing.

Sources used on this page

Pattern, shape, trap
PatternIts shapeThe planted trap
AccumulateInit, update, use afterInitialising inside the loop
Count matchesCondition guards the updateCounting the else branch too
Find maximumStart from element zero's valueStarting from literal zero
SearchReturn early on hitReturning false too early
Remove in loopBackwards, or hold the indexForward remove skips the neighbour
2D traversalRows outer, columns innerBounds swapped between loops

What does AP CSA Unit 4 cover?

Arrays, ArrayLists and 2D arrays, with the traversal patterns, accumulate, count, extreme, search, as the graded skill.

What is the difference between length and size?

Arrays expose length as a field; ArrayLists expose size as a method. Mixing the two syntaxes is a favourite distractor.

When can I not use the enhanced for?

When the loop must assign into an array of primitives or remove elements. Those jobs need the indexed loop.

Why does removing in a forward loop skip elements?

Removal shifts later elements left, so the next element slides under the current index and the increment jumps past it. Iterate backwards instead.

How do I traverse a 2D array?

Nested loops: outer over rows, inner over the row's own length. Swapping the order walks columns first.

Can I build questions from my own Unit 4 notes?

Yes. Photograph the pages or upload the PDF and the questions stay inside this unit rather than sampling the whole course.

Last updated: 2026-08-15