Firstly you can just use the primitive types:

int x = 12;
double d = 3.3456;

Secondly, you can optionally use the object wrappers for those numbers:

Integer x = new Integer(12);
Double d = new Double(3.3456);

Third, if you want the string representation you can do this simply with:

String s = Integer.toString(12);

or just:

int x;
String s = "x = " + x;

or even printf() like syntax:

int x = 12;
String s = String.format("x = %d", x);

Lastly, Java since version 5 has supported auto-boxing and unboxing, which may confuse you if you're not expecting it. For example:

Integer i = 1234; // autoboxes int to Integer

and

int i = new Integer(1234); // autounboxes Integer to an int

Just use the primitive types unless you need the Number wrappers. The most common reason to use them is to put them in collections (Lists, etc).

Answer from cletus on Stack Overflow
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome › Unit2-Using-Objects › topic-2-8-IntegerDouble.html
2.8. Wrapper Classes - Integer and Double — CSAwesome v1
The AP CSA Exam covers Java 7 which does allow using the constructor. // in older versions of Java (and on the AP exam) Integer i = new Integer(2); // create an object with 2 in it Double d = new Double(3.5); // create an object with 3.5 in it // in newer versions of Java (9+) Integer i = 2; ...
🌐
Java Guides
javaguides.net › 2018 › 08 › integer-wrapper-class-in-java.html
Integer Wrapper Class in Java
July 5, 2024 - The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int. In addition, this class provides several methods for converting an int to a String and a String to an int, as well as other constants and methods useful when dealing with an int.
People also ask

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.
🌐
fiveable.me
fiveable.me › home › ap computer science a › unit 4 – data collections study guides › topic: 4.7
AP CSA 4.7: Integer and Double Wrapper Classes | Fiveable
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.
🌐
fiveable.me
fiveable.me › home › ap computer science a › unit 4 – data collections study guides › topic: 4.7
AP CSA 4.7: Integer and Double Wrapper Classes | Fiveable
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.
🌐
fiveable.me
fiveable.me › home › ap computer science a › unit 4 – data collections study guides › topic: 4.7
AP CSA 4.7: Integer and Double Wrapper Classes | Fiveable
Top answer
1 of 5
10

Firstly you can just use the primitive types:

int x = 12;
double d = 3.3456;

Secondly, you can optionally use the object wrappers for those numbers:

Integer x = new Integer(12);
Double d = new Double(3.3456);

Third, if you want the string representation you can do this simply with:

String s = Integer.toString(12);

or just:

int x;
String s = "x = " + x;

or even printf() like syntax:

int x = 12;
String s = String.format("x = %d", x);

Lastly, Java since version 5 has supported auto-boxing and unboxing, which may confuse you if you're not expecting it. For example:

Integer i = 1234; // autoboxes int to Integer

and

int i = new Integer(1234); // autounboxes Integer to an int

Just use the primitive types unless you need the Number wrappers. The most common reason to use them is to put them in collections (Lists, etc).

2 of 5
7

What you're looking at in the first example is called autoboxing / autounboxing. Java (starting with version 5) will automatically convert between 5 and Integer.valueOf(5), which constructs a wrapper of type Integer from an int primitive. But the latter (Integer x = new Integer(12)) is absolutely correct.

It doesnt work that way in the second case, however, if you wanted to write something like 5.toString(). Autoboxing only occurs when assigning a primitive to a wrapper type, or passing a primitive where the wrapper type is expected, etc. Primitive types are not Objects and thus have no properties to be referenced.

Re: "why new", it's because all reference (non-primitive) types in Java are allocated dynamically, on the heap. So (autoboxing aside), the only way to get an Integer (or other reference type) is to explicitly allocate space for one.

🌐
W3Schools
w3schools.com › java › java_wrapper_classes.asp
Java Wrapper Classes
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects.
🌐
Programiz
programiz.com › java-programming › wrapper
Java Wrapper Class (With Examples)
For example, int a = 5; // converts into object Integer aObj = a; double b = 5.6; // converts into object Double bObj = b; This process is known as auto-boxing. To learn more, visit Java autoboxing and unboxing. Note: We can also convert primitive types into wrapper objects using Wrapper class ...
🌐
YouTube
youtube.com › watch
Classes Part 15 - Integer Wrapper Class (JAVA) - YouTube
The video looks broadly at Java's wrapper classes. It then looks at the Integer Wrapper class specifically with its attributes and methods.
Published   November 30, 2018
🌐
Fiveable
fiveable.me › home › ap computer science a › unit 4 – data collections study guides › topic: 4.7
AP CSA 4.7: Integer and Double Wrapper Classes | Fiveable
June 9, 2026 - 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.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › integer class in java
Integer Class in Java| Scaler Topics
April 14, 2024 - The Java.lang.Number package contains the Java Integer class. An int value can be successfully handled using the methods in the integer class, which is a wrapper class for the primitive type int. For example, an int value can be efficiently represented as a string and vice versa.
🌐
W3Resource
w3resource.com › java-tutorial › java-wrapper-classes.php
Java Wrapper Classes - w3resource
August 19, 2022 - The second statement instantiates an Integer object. The object is initialized with the value 33 and a reference to the object is assigned to the object variable y. Below table lists wrapper classes in Java API with constructor details. ... As explain in above table all wrapper classes (except Character) take String as argument constructor. Please note we might get NumberFormatException if we try to assign invalid argument in the constructor. For example ...
🌐
Open Book Project
openbookproject.net › thinkcs › archive › java › english › app01.htm
Wrapper classes
In other words, you can wrap a primitive value up in an object, which is useful if you want to invoke a method that requires an object type. The most straightforward way to create a wrapper object is to use its constructor: Integer i = new Integer (17); Double d = new Double (3.14159); Character ...
🌐
Codekru
codekru.com › home › integer wrapper class in java
Integer Wrapper class in Java - Codekru
November 20, 2022 - We can compare two integer objects using the equals() method or the comparison operator ( == ). equals() method compares the primitive values stored by a wrapper instance, whereas == compares the object references only. Let’s show you this with an example. public class Codekru { public static void main(String[] args) { Integer i1 = Integer.valueOf(1234); Integer i2 = Integer.valueOf(1234); if (i1.equals(i2)) { System.out.println("Both are equal"); } else { System.out.println("Both aren't equal"); } } }
🌐
Nus-cs2030s
nus-cs2030s.github.io › 2021-s2 › 16-wrapper.html
16. Wrapper Class - CS2030S Programming Methodology II
As conversion back-and-fro between ... type and its wrapper class. ... The first statement is an example of auto-boxing, where the primitive value int of 4 is converted into an instance of Integer....
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit2-Using-Objects › topic-2-8-IntegerDouble.html
2.8. Wrapper Classes - Integer and Double — CS Java
For every primitive type in Java, there is a built-in object type called a wrapper class. The wrapper class for int is called Integer, and for double it is called Double. Sometimes you may need to create a wrapped object for a primitive type so that you can give it to a method that is expecting ...
🌐
LabEx
labex.io › tutorials › java-how-to-create-integer-wrapper-object-420416
How to create Integer wrapper object | LabEx
In Java programming, understanding how to create Integer wrapper objects is crucial for developers seeking to work with numeric data types effectively. This tutorial explores various methods of creating Integer objects, demonstrating the flexibility and power of Java's wrapper classes in handling ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-integer-class-java
Java.lang.Integer class in Java - GeeksforGeeks
June 21, 2022 - Space of constants: It is just to imagine for better understanding that there is some space for constants in heap memory. Example: Integer x = 200; //initializing directly x = 300; //modifying x x = 10; //modifying x again ·
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome2 › topic-4-7-wrapper-classes.html
4.7 Wrapper Classes - Integer and Double
The wrapper classes are also used ... examples of creating Integer and Double objects. In Java version 7, you can use a constructor like new Integer(2) to create an object with the value 2 in it....
🌐
Scientech Easy
scientecheasy.com › home › blog › wrapper classes in java (with examples)
Wrapper Classes in Java (with Examples) - Scientech Easy
February 3, 2025 - Output: Displaying values of Wrapper class objects: Character object: a Byte object: 10 Integer object: 20 Float object: 18.6 Double object: 250.5 Displaying unwrapped values: char value: a byte value: 10 int value: 20 float value: 18.6 double value: 250.5 · 1. Wrapper class in Java provides several constructors, constants, and conversion methods for manipulating various primitive data type values.
🌐
BeginnersBook
beginnersbook.com › 2017 › 09 › wrapper-class-in-java
Wrapper class in Java
November 8, 2022 - Lets take few examples to understand how the conversion works: public class JavaExample{ public static void main(String args[]){ //Converting int primitive into Integer object int num=100; Integer obj=Integer.valueOf(num); System.out.println(num+ " "+ obj); } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › wrapper-classes-java
Wrapper Classes in Java - GeeksforGeeks
class Geeks { public static void main(String[] args) { int b = 357; // Autoboxing: primitive int -> Integer object Integer a = b; System.out.println("The primitive int b is: " + b); System.out.println("The Integer object a is: " + a); } } ... ...
Published   April 6, 2026
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Integer.html
Integer (Java Platform SE 8 )
April 21, 2026 - Java™ Platform Standard Ed. 8 ... The Integer class wraps a value of the primitive type int in an object.