---
title: "AP CSA 4.7: Integer and Double Wrapper Classes"
description: "Learn how Integer and Double wrapper classes work in AP Computer Science A, including autoboxing, unboxing, parseInt, and parseDouble."
canonical: "https://fiveable.me/ap-comp-sci-a/unit-4/wrapper-classes-integer-double/study-guide/CKbVZpoW1SH2jmwauzDE"
type: "study-guide"
subject: "AP Computer Science A"
unit: "Unit 4 – Data Collections"
lastUpdated: "2026-06-09"
---

# AP CSA 4.7: Integer and Double Wrapper Classes

## Summary

Learn how Integer and Double wrapper classes work in AP Computer Science A, including autoboxing, unboxing, parseInt, and parseDouble.

## Guide

Wrapper classes let you use `Integer` and `Double` [objects](/ap-comp-sci-a/key-terms/object "fv-autolink") 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](/ap-comp-sci-a "fv-autolink"), 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](/ap-comp-sci-a/unit-4 "fv-autolink"), 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](/ap-comp-sci-a/key-terms/list "fv-autolink") stores wrapper objects, even though you often write plain numbers thanks to autoboxing.

The two [methods](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink") you are responsible for from the Java Quick [Reference](/ap-comp-sci-a/key-terms/reference "fv-autolink") 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

- `Integer` and `Double` are wrapper classes in the `java.lang` [package](/ap-comp-sci-a/key-terms/package "fv-autolink"), so no import is needed, and both are [immutable](/ap-comp-sci-a/key-terms/immutable "fv-autolink") 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](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink") 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 an `int`, and `Double.parseDouble(String s)` returns a `double`.
- Wrapper objects are needed for collections like `ArrayList`, which store [object references](/ap-comp-sci-a/key-terms/object-reference "fv-autolink") 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](/ap-comp-sci-a/key-terms/import-statement "fv-autolink") 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](/ap-comp-sci-a/key-terms/compiler "fv-autolink") 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](/ap-comp-sci-a/key-terms/parameter "fv-autolink") to a method that expects the wrapper class.

```java
Integer 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](/ap-comp-sci-a/unit-4/developing-algorithms-using-arraylists/study-guide/MKbteieYvLOpWIwfqiND "fv-autolink"): 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.

```java
Integer 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](/ap-comp-sci-a/unit-1/calling-non-void-method/study-guide/gXkdn6sNrkDRHZsCVN1x "fv-autolink") methods convert text into numbers, and both are on the Java Quick Reference:

- `Integer.parseInt(String s)` returns the `String` [argument](/ap-comp-sci-a/key-terms/argument "fv-autolink") as an `int`.
- `Double.parseDouble(String s)` returns the `String` argument as a `double`.

```java
int 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](/ap-comp-sci-a/unit-4/arraylist-methods/study-guide/8juIkbLwLGELYtblBeCf "fv-autolink"). You cannot change the value inside an existing `Integer` or `Double`; 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.parseInt` and `Double.parseDouble` return primitives, not wrapper objects. `parseInt` returns an `int` and `parseDouble` returns a `double`.
- `Integer` and `Double` do not require an import. They are part of `java.lang`, which is always available, unlike `ArrayList` from `java.util`.
- Storing numbers in an `ArrayList` does not store primitives. The list holds `Integer` or `Double` objects, and autoboxing is what lets you add plain numbers to it.

## Related AP Computer Science A Guides

- [4.11 2D Arrays](/ap-comp-sci-a/unit-4/2d-arrays/study-guide/5WDx6ZFeWhx2aVuiZI6R)
- [4.15 Sorting](/ap-comp-sci-a/unit-4/sorting/study-guide/P5PACxSTKavEy6V3x3Nt)
- [4.1 Ethical and Social Implications](/ap-comp-sci-a/unit-4/ethical-and-social-implications/study-guide/iec7yzDQ2qENx5UAdiPJ)
- [4.9 Traversing ArrayLists](/ap-comp-sci-a/unit-4/traversing-arraylists/study-guide/U4SdcheNw5PMSIzjU2oL)
- [4.5 Developing Algorithms Using Arrays](/ap-comp-sci-a/unit-4/developing-algorithms-using-arrays/study-guide/c6dpJfmjG7oVFDqnXFAk)
- [4.16 Recursion](/ap-comp-sci-a/unit-4/recursion/study-guide/p4D3YegZCLwQ3KJVvsd4)

## Vocabulary

- **Double class**: A wrapper class in the java.lang package that represents a primitive double value as an object; Double objects are immutable.
- **Integer class**: A wrapper class in the java.lang package that represents a primitive int value as an object; Integer objects are immutable.
- **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.
- **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.
- **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.

## FAQs

### 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.

## Structured Data

```json
{"@context":"https://schema.org","@type":"FAQPage","inLanguage":"en","mainEntity":[{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-4/wrapper-classes-integer-double/study-guide/CKbVZpoW1SH2jmwauzDE#what-is-a-wrapper-class-in-ap-computer-science-a","name":"What is a wrapper class in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-4/wrapper-classes-integer-double/study-guide/CKbVZpoW1SH2jmwauzDE#are-integer-and-double-part-of-javalang","name":"Are Integer and Double part of java.lang?","acceptedAnswer":{"@type":"Answer","text":"Yes. Integer and Double are part of the java.lang package, so they are available automatically and do not require an import statement."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-4/wrapper-classes-integer-double/study-guide/CKbVZpoW1SH2jmwauzDE#what-does-immutable-mean-for-integer-and-double-objects","name":"What does immutable mean for Integer and Double objects?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-4/wrapper-classes-integer-double/study-guide/CKbVZpoW1SH2jmwauzDE#what-is-autoboxing-in-java","name":"What is autoboxing in Java?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-4/wrapper-classes-integer-double/study-guide/CKbVZpoW1SH2jmwauzDE#what-is-unboxing-in-java","name":"What is unboxing in Java?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-4/wrapper-classes-integer-double/study-guide/CKbVZpoW1SH2jmwauzDE#what-do-parseint-and-parsedouble-return","name":"What do parseInt and parseDouble return?","acceptedAnswer":{"@type":"Answer","text":"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."}}]}
```
