Skip to main content
← AP CSA Study Guide

Unit 6 · Heavy

ArrayList and Wrapper Classes

A resizable list of objects. The unit adds one genuinely tricky behavior: removing during a traversal shifts every later element, so the loop and the list disagree about where things are.

What a strong answer looks like

A strong Unit 6 answer accounts for the shift after every insertion or removal, and states the size at the moment each index is used.

Topics in this unit

1

ArrayList Basics

Practice this topic →

Know

An ArrayList grows and shrinks, reports size() as a method, and stores objects rather than primitives.

Apply

Use size() for bounds and get() for access, keeping in mind both change as the list is modified.

Watch out

Using length or length() on an ArrayList, or an index equal to size().

Study move

Write a loop over an ArrayList and state the valid index range at each step.

2

ArrayList Insert and Remove

Practice this topic →

Know

Removing an element shifts every later element down by one and reduces size. Inserting shifts them up.

Apply

When removing inside a loop, either iterate backwards or avoid advancing the index after a removal.

Watch out

Removing while iterating forwards with a normal increment, which silently skips the element after each removal.

Study move

Remove every negative value from a list twice, once forwards and once backwards, and compare results.

3

ArrayList Traversal

Practice this topic →

Know

Traversal mirrors arrays but bounds come from size(), which is re-evaluated each pass and can change mid-loop.

Apply

Decide before writing the loop whether the list will change during it.

Watch out

Caching size() in a variable and then modifying the list, so the bound no longer matches.

Study move

Trace a loop that adds an element on a condition and explain the effect on the bound.

4

ArrayList and Wrapper Classes

Practice this topic →

Know

ArrayList holds objects, so primitives are wrapped. Autoboxing hides the conversion, but equality comparison on wrappers is not the same as on primitives.

Apply

Compare wrapper values with equals rather than the equality operator.

Watch out

Comparing two wrapper objects with the equality operator, which compares references and can be false for equal values.

Study move

Compare two equal wrapper values both ways and explain the difference in result.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • Accounting for the shift after every insertion and removal
  • Re-reading size() rather than caching it across a modifying loop
  • Using equals for wrapper comparison

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • Iterator. Taught in some classes; the exam expects index-based and enhanced for traversal.
  • Generics beyond one type. Class projects go further than the exam requires.

Mastery checklist

  • Give the valid index range of an ArrayList of size n.
  • Remove elements during traversal without skipping any.
  • Explain what happens to indexes after a removal.
  • Compare two wrapper values correctly.

Check yourself

  • Why does removing forwards with a normal increment skip elements?
  • What changes when size() is cached before a modifying loop?
  • Why can the equality operator be false for two equal wrapper values?

Modeling drill

Write code that removes every element below a threshold from an ArrayList, and state why your loop does not skip any.

size()getaddremoveShiftWrapper classAutoboxingequals