AP CSA Unit 4.7: Wrapper Classes and Autoboxing Practice
Share
Unit 4, Section 4.7
Day 7 Practice • January 13, 2026
🎯 Focus: Wrapper Classes and ArrayList
Practice Question
Consider the following code segment:
ArrayList<Integer> nums = new ArrayList<Integer>();
nums.add(5);
nums.add(10);
int sum = nums.get(0) + nums.get(1);
System.out.println(sum);
What is printed as a result of executing this code segment?
What This Tests: Section 4.7 covers wrapper classes. ArrayLists can only hold objects, not primitives. Java automatically converts between int and Integer (autoboxing/unboxing), making this code work seamlessly.
Autoboxing and Unboxing
// AUTOBOXING: int → Integer (automatic)
nums.add(5); // 5 (int) becomes Integer.valueOf(5)
nums.add(10); // 10 (int) becomes Integer.valueOf(10)
// UNBOXING: Integer → int (automatic)
nums.get(0) // Returns Integer, auto-converts to int
nums.get(0) + nums.get(1) // 5 + 10 = 15
Step-by-Step Trace
| Line | Action | nums |
|---|---|---|
| 1 | Create empty ArrayList | [] |
| 2 | add(5) - autoboxed | [5] |
| 3 | add(10) - autoboxed | [5, 10] |
| 4 | get(0) + get(1) = 5 + 10 | 15 |
Wrapper Classes
Primitive → Wrapper
int → Integer
double → Double
boolean → Boolean
char → Character
ArrayLists require wrapper classes: ArrayList<Integer> not ArrayList<int>
Common Mistakes
Mistake: Answer A (510)
This would happen with String concatenation. But we're adding int values: 5 + 10 = 15, not "5" + "10" = "510".
Mistake: Answer C or D (Error)
Autoboxing and unboxing handle the conversion automatically. No errors occur!
Difficulty: Medium • Time: 2-3 minutes • AP Skill: 3.D - Wrapper classes
Completed Unit 4 Week 1! 🎉
Great job finishing all 7 days of data collections!
Premium Question Bank - Coming Soon Schedule 1-on-1 Tutoring