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
🌐
W3Schools
w3schools.com › java › java_wrapper_classes.asp
Java Wrapper Classes
Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects. The table below shows the primitive type and the equivalent wrapper class: Sometimes you must use wrapper classes, for example when working with Collection ...
🌐
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 ...
🌐
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.
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.

🌐
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.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Integer.html
Integer (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... The Integer class wraps a value of the primitive type int in an object.
🌐
Fiveable
fiveable.me › all study guides › ap computer science a › unit 4 – data collections study guides › topic: 4.7
Wrapper Classes: Integer and Double - AP Computer Science A | Fiveable
August 22, 2025 - Wrapper classes bridge the gap between primitive data types and objects in Java. The Integer class, which wraps the primitive int type, enables you to treat numeric values as objects when needed - particularly in collections like ArrayList that can only store objects, not primitives.
🌐
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 ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › wrapper-classes-java
Wrapper Classes in Java - GeeksforGeeks
This enables primitives to be used in object-oriented features such as collections, generics, and APIs that require objects. Each wrapper class encapsulates a corresponding primitive value inside an object (e.g., Integer for int, Double for double).
Published   December 20, 2016
🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
W3Resource
w3resource.com › java-tutorial › java-wrapper-classes.php
Java Wrapper Classes - w3resource
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 ...
🌐
Fiveable
fiveable.me › all study guides › ap computer science a › unit 4 – data collections study guides › topic: 4.7
Wrapper Classes: Integer and Double - AP Computer Science... | Fiveable
September 18, 2025 - Wrapper classes bridge the gap between primitive data types and objects in Java. The Integer class, which wraps the primitive int type, enables you to treat numeric values as objects when needed - particularly in collections like ArrayList that can only store objects, not primitives.
🌐
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.
🌐
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.
🌐
Hero Vired
herovired.com › learning-hub › blogs › wrapper-class-in-java
Wrapper Classes in Java: Types, Uses, Examples & Advantages
By learning polymorphism in java, you can understand the concept of Wrapper classes better. Moreover, you can also attend a course on Java programming language. ... An Integer wrapper class wraps around an int primitive.
🌐
Runestone Academy
runestone.academy › ns › books › published › BHSawesome2 › topic-4-7-wrapper-classes.html
Wrapper classes
Java’s solution to this problem is to define wrapper classes, classes that exist to provide a reference type that wraps up a single value of a given primitive type. These types are defined in the java.lang pacakge and have names that are the capitalized, unabbreviated names of the corresponding ...
🌐
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?
November 4, 2022 -

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.