Wrapper classes let you use Integer and Double objects in places that need objects instead of primitives, like an ArrayList. Java handles conversions automatically through autoboxing from primitive to wrapper and unboxing from wrapper to primitive, and you can turn a String into a number with Integer.parseInt or Double.parseDouble. For AP Computer Science A, track whether a value is a primitive, wrapper object, or parsed number.
Why This Matters for the AP Computer Science A Exam
Wrapper classes are the link between primitive values and the object-based collections you use later in Unit 4, like ArrayList. On the AP Computer Science A exam, this shows up when you trace code that mixes int and Integer (or double and Double) and need to predict the result. Free-response code writing that builds and processes an ArrayList of numbers depends on understanding that the list stores wrapper objects, even though you often write plain numbers thanks to autoboxing.
The two methods you are responsible for from the Java Quick Reference are Integer.parseInt(String s) and Double.parseDouble(String s). Knowing exactly what those return helps you read data and convert text into numbers you can compute with.

Key Takeaways
IntegerandDoubleare wrapper classes in thejava.langpackage, so no import is needed, and both are immutable once created.- Autoboxing converts a primitive to its wrapper automatically; unboxing converts a wrapper back to a primitive automatically.
- Java autoboxes when a primitive is assigned to a wrapper variable or passed to a method expecting that wrapper.
- Java unboxes when a wrapper is assigned to a primitive variable or passed to a method expecting that primitive.
Integer.parseInt(String s)returns anint, andDouble.parseDouble(String s)returns adouble.- Wrapper objects are needed for collections like
ArrayList, which store object references rather than primitives.
Key Concepts
Integer and Double Are Wrapper Classes
A wrapper class gives a primitive value an object form. The Integer class wraps an int, and the Double class wraps a double. Both live in the java.lang package, which is available automatically, so you do not write an import statement to use them.
Both Integer and Double are immutable. Once an Integer or Double object is created, its value cannot be changed. If you need a different value, you create a new object rather than modifying the existing one.
The main reason wrapper classes exist for the exam is that some structures only hold objects, not primitives. An ArrayList stores object references, so you store numbers as Integer or Double objects rather than as raw int or double values.
Autoboxing: Primitive to Wrapper
Autoboxing is the automatic conversion the Java compiler makes from a primitive to its matching wrapper class. This includes turning an int into an Integer and a double into a Double. You do not write any special code; the compiler does it for you.
Autoboxing happens in two situations:
- A primitive value is assigned to a variable of the wrapper class.
- A primitive value is passed as a parameter to a method that expects the wrapper class.
</>JavaInteger count = 42; // int 42 is autoboxed into an Integer Double price = 3.99; // double 3.99 is autoboxed into a Double ArrayList<Integer> nums = new ArrayList<Integer>(); nums.add(10); // int 10 is autoboxed before being added
In the add call, the list expects an Integer, so the int literal 10 is autoboxed automatically.
Unboxing: Wrapper to Primitive
Unboxing is the reverse: the automatic conversion from a wrapper object back to its primitive type. This includes turning an Integer into an int and a Double into a double.
Unboxing happens in two situations:
- A wrapper object is assigned to a variable of the matching primitive type.
- A wrapper object is passed as a parameter to a method that expects the matching primitive.
</>JavaInteger boxed = 7; int value = boxed; // Integer is unboxed into an int ArrayList<Integer> nums = new ArrayList<Integer>(); nums.add(5); int first = nums.get(0); // get(0) returns an Integer, which is unboxed to int int total = 0; for (Integer n : nums) { total += n; // n is unboxed to int for the addition }
Because autoboxing and unboxing are automatic, you can often write code with plain numbers and let the compiler handle the conversions. The skill the exam tests is recognizing where those conversions happen so you can predict the result.
Converting Strings to Numbers
Two static methods convert text into numbers, and both are on the Java Quick Reference:
Integer.parseInt(String s)returns theStringargument as anint.Double.parseDouble(String s)returns theStringargument as adouble.
</>Javaint n = Integer.parseInt("123"); // n is 123 double d = Double.parseDouble("3.14"); // d is 3.14
These are useful when data comes in as text and you need an actual number to compute with. Notice that parseInt returns a primitive int and parseDouble returns a primitive double, not wrapper objects.
How to Use This on the AP Computer Science A Exam
Code Tracing
When you trace code that mixes primitives and wrappers, label each conversion as you go. If a primitive is assigned to a wrapper variable or passed where a wrapper is expected, that is autoboxing. If a wrapper is assigned to a primitive variable or passed where a primitive is expected, that is unboxing. Tracking these conversions keeps you from getting confused about which type a variable holds.
For ArrayList<Integer>, remember that add autoboxes the number going in and get returns an Integer that gets unboxed when you store it in an int or use it in arithmetic.
Free Response
Free-response code writing that processes a collection of numbers usually relies on autoboxing and unboxing. When you build an ArrayList<Integer>, you can add plain int values and they are boxed automatically. When you sum or compare elements, the wrappers are unboxed for the arithmetic. Write the natural code with numbers and trust the automatic conversions, but know that the list holds Integer objects.
Common Trap
If you need to turn a String into a number, reach for Integer.parseInt or Double.parseDouble. Mixing them up, such as using parseInt on "3.14", gives you the wrong result for the data. Match the method to the type you actually need.
Common Misconceptions
- Wrapper objects are not mutable. You cannot change the value inside an existing
IntegerorDouble; you make a new object instead. - Autoboxing and unboxing are not something you type. The compiler inserts these conversions automatically based on the types involved.
Integer.parseIntandDouble.parseDoublereturn primitives, not wrapper objects.parseIntreturns anintandparseDoublereturns adouble.IntegerandDoubledo not require an import. They are part ofjava.lang, which is always available, unlikeArrayListfromjava.util.- Storing numbers in an
ArrayListdoes not store primitives. The list holdsIntegerorDoubleobjects, and autoboxing is what lets you add plain numbers to it.
Related AP Computer Science A Guides
Vocabulary
The following words are mentioned explicitly in the College Board Course and Exam Description for this topic.Term | Definition |
|---|---|
autoboxing | The automatic conversion by the Java compiler from a primitive type to its corresponding wrapper class object, such as converting an int to an Integer or a double to a Double. |
Double class | A wrapper class in the java.lang package that represents a primitive double value as an object; Double objects are immutable. |
immutable | A property of String objects meaning that once created, their content cannot be changed; methods called on a String return a new String rather than modifying the original. |
Integer class | A wrapper class in the java.lang package that represents a primitive int value as an object; Integer objects are immutable. |
parseDouble | A static method of the Double class that converts a String argument to a double value. |
parseInt | A static method of the Integer class that converts a String argument to an int value. |
primitive type | A basic data type in Java such as int or double that is not an object. |
unboxing | The automatic conversion by the Java compiler from a wrapper class object to its corresponding primitive type, such as converting an Integer to an int or a Double to a double. |
wrapper class | A class that encapsulates a primitive data type and provides object-oriented functionality, such as Integer and Double. |
Frequently Asked Questions
What is a wrapper class in AP Computer Science A?
A wrapper class gives a primitive value an object form. In AP CSA, the tested wrapper classes are Integer for int values and Double for double values.
Are Integer and Double part of java.lang?
Yes. Integer and Double are part of the java.lang package, so they are available automatically and do not require an import statement.
What does immutable mean for Integer and Double objects?
Immutable means the object cannot be changed after it is created. If an Integer or Double needs a different value, Java creates or assigns a different object rather than changing the original object.
What is autoboxing in Java?
Autoboxing is the automatic conversion from a primitive to its matching wrapper class, such as int to Integer or double to Double. It happens when a primitive is assigned to a wrapper variable or passed to a method expecting a wrapper.
What is unboxing in Java?
Unboxing is the automatic conversion from a wrapper object back to the matching primitive type, such as Integer to int or Double to double. It happens when a wrapper is assigned to a primitive variable or passed to a method expecting a primitive.
What do parseInt and parseDouble return?
Integer.parseInt(String s) returns an int, and Double.parseDouble(String s) returns a double. Both methods convert a String into a primitive number, not a wrapper object.