Unit 4 · Data Collections
ArrayList Insert and Remove
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What arraylist insert and remove covers
The two-argument add(index, value) inserts at a position and shifts every later element one slot to the right, increasing size by one. The remove(index) call deletes an element, shifts later elements left, and returns the removed value. Because both operations renumber everything after the change point, the index that was correct before the call is usually not correct after it.
Where students lose points
Removing inside a forward loop skips the element that slides into the vacated position, so consecutive matches survive. The fixes are to iterate backward or to avoid incrementing after a removal. Students also call remove with an Integer value and get the index-based overload instead of the value-based one.
How it shows up on the AP exam
Unit 4 material and a reliably high-value MCQ topic precisely because the shifting behavior is counterintuitive. Removal-during-traversal is a recurring FRQ trap.
For practice use only.
ArrayList Insert and Remove MCQ Practice
AP CSA ArrayList insert and remove practice: how indexes shift after each change, the skipped-element bug, and safe backward traversal.
Answered 0 of 15
Choose one answer.
Which option matches the complete output produced by this segment?
public class ArrayListInsertAndRemoveContext
{
public static void runExample()
{
ArrayList<Integer> a = new ArrayList<Integer>();
a.add(1);
a.add(2);
a.add(3);
a.remove(1);
System.out.print(a);
}
public static void main(String[] args)
{
runExample();
}
}