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
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 ...
🌐
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.
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
🌐
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, ...
🌐
Java Guides
javaguides.net › 2018 › 08 › integer-wrapper-class-in-java.html
Integer Wrapper Class in Java
July 5, 2024 - The Integer class in Java is a wrapper class for the primitive data type int. It is part of the java.lang package and provides various methods to work with integers, such as parsing, converting, and comparing them.
🌐
W3Schools
w3schools.com › java › java_wrapper_classes.asp
Java Wrapper Classes
Sometimes you must use wrapper classes, for example when working with Collection objects, such as ArrayList, where primitive types cannot be used (the list can only store objects): ArrayList<int> myNumbers = new ArrayList<int>(); // Invalid · ArrayList<Integer> myNumbers = new ArrayList<Integer>(); // Valid
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.

Find elsewhere
🌐
W3Resource
w3resource.com › java-tutorial › java-wrapper-classes.php
Java Wrapper Classes - w3resource
August 19, 2022 - The first statement declares an int variable named x and initializes it with the value 25. 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 ...
🌐
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.
🌐
CodeGym
codegym.cc › java blog › java classes › java.lang.integer class
Java.lang.Integer Class
February 20, 2025 - A reference data type that "wraps" or turns its primitive little brother in a Java object. Integer is a wrapper class for its primitive bro named int. Integer in English means a whole number.
🌐
Codekru
codekru.com › home › integer wrapper class in java
Integer Wrapper class in Java - Codekru
November 20, 2022 - We have wrapper classes in Java that provide a mechanism to wrap primitive values in an object so that primitives can be used for the operations reserved only for objects. One such wrapper class is the Integer wrapper class which wraps an int primitive to facilitate object operations.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-integer-class-java
Java.lang.Integer class in Java - GeeksforGeeks
June 21, 2022 - Integer class is a wrapper class for the primitive type int which contains several methods to effectively deal with an int value like converting it to a string representation, and vice-versa.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › Integer.html
Integer (Java Platform SE 7 )
Java™ Platform Standard Ed. 7 ... The Integer class wraps a value of the primitive type int in an object.
🌐
LabEx
labex.io › tutorials › java-how-to-create-integer-wrapper-object-420416
How to create Integer wrapper object | LabEx
In Java, the Integer wrapper class is a fundamental part of the Java language that encapsulates the primitive int data type within an object.
🌐
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 ...
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome2 › topic-4-7-wrapper-classes.html
4.7 Wrapper Classes - Integer and Double
A wrapper class is a class that ... into all Java programs. The Integer class and Double class are wrapper classes that create objects from primitive types of int and double respectively....
🌐
Nus-cs2030s
nus-cs2030s.github.io › 2021-s2 › 16-wrapper.html
16. Wrapper Class - CS2030S Programming Methodology II
A wrapper class is a class that encapsulates a type, rather than fields and methods. The wrapper class for int is called Integer, for double is called Double, etc. A wrapper class can be used just like every other class in Java and behave just like every other class in Java.
🌐
Reddit
reddit.com › r/learnjava › why is the wrapper class name for int integer and not int?
r/learnjava on Reddit: Why is the wrapper class name for int Integer and not Int?
February 2, 2023 -

I understand what the purpose of the wrapper classes is but the naming convention confuses me?

double is Double, float is Float, boolean is Boolean so why is int Integer?

Is it that way just because it is and always has been? Or is it something to do with humans may not see a difference between an uppercase "I" vs a lowercase "i" in some fonts.

🌐
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 ...
🌐
Programiz
programiz.com › java-programming › wrapper
Java Wrapper Class (With Examples)
The wrapper classes in Java are used to convert primitive types (int, char, float, etc) into corresponding objects. Each of the 8 primitive types has corresponding wrapper classes. We can also use the valueOf() method to convert primitive types into corresponding objects. class Main { public ...