Unit 4 · Data Collections
ArrayList and Wrapper Classes
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What arraylist and wrapper classes covers
Because generics require class types, numeric ArrayLists store Integer and Double objects rather than int and double. Java autoboxes primitives into wrappers on the way in and unboxes them on the way out, so list.add(5) and int x = list.get(0); both compile. The values still behave like objects, which matters for comparison and for method overload resolution.
Where students lose points
Comparing wrappers with == compares references, and it fails outside the small cached integer range even when the numeric values match, so equals is the correct choice. The remove overloads are the other trap: remove(2) deletes the element at index 2, while remove(Integer.valueOf(2)) deletes the first element equal to 2.
How it shows up on the AP exam
Unit 4 material that the exam tests through subtle comparison and overload questions rather than through syntax. Knowing when unboxing happens explains most of the surprising answers.
For practice use only.
ArrayList and Wrapper Classes MCQ Practice
AP CSA wrapper class practice: Integer and Double autoboxing, unboxing in arithmetic, equals versus == for wrappers, and remove overload confusion.
Answered 0 of 15
Choose one answer.
Which option matches the complete output produced by this segment?
public class ArrayListAndWrapperClassesContext
{
public static void runExample()
{
ArrayList<Integer> a = new ArrayList<Integer>();
a.add(5);
int x = a.get(0);
System.out.print(x + 1);
}
public static void main(String[] args)
{
runExample();
}
}