Unit 4 · Data Collections
ArrayList Basics
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What arraylist basics covers
An ArrayList grows and shrinks at runtime, unlike a fixed-size array. It reports its size through size(), reads with get(i), replaces with set(i, value), and appends with add(value). The type parameter must be a class type, so an ArrayList of integers is declared as ArrayList<Integer> rather than ArrayList<int>. Valid indexes still run from 0 through size() - 1.
Where students lose points
Mixing up the three accessors is constant: length for arrays, length() for Strings, size() for ArrayList. Students also index with square brackets instead of get, declare ArrayList<int>, and assume set adds a new element when it only replaces an existing one.
How it shows up on the AP exam
Unit 4 data collections. ArrayList appears in roughly every exam administration, and the API details are exactly what the multiple-choice section checks.
For practice use only.
ArrayList Basics MCQ Practice
AP CSA ArrayList basics practice: size versus length, get and set, adding elements, and the generic type rules the exam expects.
Answered 0 of 15
Choose one answer.
Which option matches the complete output produced by this segment?
public class ArrayListBasicsContext
{
public static void runExample()
{
ArrayList<Integer> a = new ArrayList<Integer>();
a.add(5);
a.add(9);
System.out.print(a.size() + " " + a.get(0));
}
public static void main(String[] args)
{
runExample();
}
}