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
๐ŸŒ
Java Guides
javaguides.net โ€บ 2018 โ€บ 08 โ€บ integer-wrapper-class-in-java.html
Integer Wrapper Class in Java
July 5, 2024 - Immutability: Instances of the Integer class are immutable. Constants: Provides constants like MIN_VALUE and MAX_VALUE. Static Methods: Methods for parsing strings to integers, comparing integers, and converting integers to strings. Here are some commonly used methods in the Integer class:
๐ŸŒ
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
This includes converting an Integer to an int and a Double to a double. The Java compiler applies unboxing when a wrapper class object is passed as a parameter to a method that expects a value of the corresponding primitive type or assigned to a variable of the corresponding primitive type.
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
๐ŸŒ
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. 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 ...
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_wrapper_classes.asp
Java Wrapper Classes
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ wrapper
Java Wrapper Class (With Examples)
We can also use the valueOf() method to convert primitive types into corresponding objects. class Main { public static void main(String[] args) { // create primitive types int a = 5; double b = 5.65; //converts into wrapper objects Integer aObj = Integer.valueOf(a); Double bObj = Double.valueOf(b); ...
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.

๐ŸŒ
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. 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 ...
Find elsewhere
๐ŸŒ
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 - 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.
๐ŸŒ
Decodejava
decodejava.com โ€บ java-integer-class.htm
Java Integer Class- Decodejava.com
Integer wrapper class is used to create an object version of a primitive int value. class A { public static void main(String... ar) { Integer b1 = new Integer(10); //Passing a primitive int value. Integer b2 = new Integer("20"); //Passing primitive int as a String.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ java-how-to-create-integer-wrapper-object-420416
How to create Integer wrapper object | LabEx
It provides a way to treat integers as objects, enabling them to be used in situations that require objects rather than primitive types. graph TD A[Primitive int] --> B[Integer Wrapper] B --> C[Object-based Representation] B --> D[Additional ...
๐ŸŒ
Codekru
codekru.com โ€บ home โ€บ integer wrapper class in java
Integer Wrapper class in Java - Codekru
November 20, 2022 - On the other hand, the equals() method compares the value and not the references. Because of this, i1.equals(i2) returned true as both the integers have the same value despite being two different instances. Integer wrapper classes cache the wrapper objects for values between -128 to 127.
๐ŸŒ
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 API with constructor details.
๐ŸŒ
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.
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ csawesome2 โ€บ topic-4-7-wrapper-classes.html
4.7 Wrapper Classes - Integer and Double
This includes converting an Integer to an int and a Double to a double. The Java compiler applies unboxing when a wrapper class object is passed as a parameter to a method that expects a value of the corresponding primitive type or assigned to a variable of the corresponding primitive type.
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
Nus-cs2030s
nus-cs2030s.github.io โ€บ 2021-s2 โ€บ 16-wrapper.html
16. Wrapper Class - CS2030S Programming Methodology II
With the wrapper type, we can reuse our contains method that takes in an Object array as a parameter to operate on an array of integers -- we just need to pass our integers into the method in an Integer array instead of an int array. All primitive wrapper class objects are immutable -- once ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ wrapper-classes-java
Wrapper Classes in Java - GeeksforGeeks
Wrapper classes are required in ... only objects, not primitives. Wrapper objects allow primitives to be used in object-oriented features like methods, synchronization, and serialization....
Published ย  April 6, 2026
๐ŸŒ
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
This includes converting an Integer to an int and a Double to a double. The Java compiler applies unboxing when a wrapper class object is passed as a parameter to a method that expects a value of the corresponding primitive type or assigned to a variable of the corresponding primitive type.