You can use

Integer integer = Integer.valueOf(i);

From the javadoc of the constructor:

Deprecated. It is rarely appropriate to use this constructor. The static factory valueOf(int) is generally a better choice, as it is likely to yield significantly better space and time performance. Constructs a newly allocated Integer object that represents the specified int value.

The main difference is that you won't always get a new instance with valueOf as small Integer instances are cached.


All of the primitive wrapper types (Boolean, Byte, Char, Short, Integer, Long, Float and Double) have adopted the same pattern. In general, replace:

    new <WrapperType>(<primitiveType>)

with

    <WrapperType>.valueOf(<primitiveType>)

(Note that the caching behavior mentioned above differs with the type and the Java platform, but the Java 9+ deprecation applies notwithstanding these differences.)

Answer from Denys Séguret on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Integer.html
Integer (Java Platform SE 8 )
April 21, 2026 - The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string. In other words, this method returns an Integer object equal to the value of: ... NumberFormatException - if the string cannot be parsed as an integer. ... Returns an Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values.
🌐
CodeGym
codegym.cc › java blog › java classes › java.lang.integer class
Java.lang.Integer Class
February 20, 2025 - public Integer(String s) throws NumberFormatException. Here s is a string representation of the int value. This constructor creates an Integer object that was initialised with the int value provided by string representation.
🌐
Scaler
scaler.com › home › topics › integer class in java
Integer Class in Java| Scaler Topics
April 14, 2024 - In the above code, the Integer string is passed using a constructor so that it will create an object of the Integer class with an Integer value of 12. In the 8th line of code, the Integer class Object is created using int value, which will create an object of the Integer class with value 12. In the below code, we are going to see examples of the method of the Integers class that we discussed above. ... In Java, an integer class contains a value of the primitive type int within an object.
🌐
Java2s
java2s.com › Tutorials › Java › Data_Types › How_to_create_Java_Integer_using_its_constructors.htm
How to create Java Integer using its constructors
How to create Integer using its constructors · Integer(int value) creates an Integer object for the int value. Integer(String s) creates an Integer object for the int value indicated by s. public class Main { public static void main(String[] args) { //from j a v a 2 s .c om ·
🌐
Oracle
docs.oracle.com › javase › 10 › docs › api › java › lang › Integer.html
Integer (Java SE 10 & JDK 10 )
The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string. In other words, this method returns an Integer object equal to the value of: ... NumberFormatException - if the string cannot be parsed as an integer. ... Returns an Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values.
🌐
TutorialsPoint
tutorialspoint.com › create-an-integer-object-in-java
Create an Integer object in Java
December 18, 2024 - The Integer class is a wrapper class in Java, which can be used to encapsulate a primitive int value in an object. You can create an Integer object using the Integer constructor by passing a primitive int value.
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › Integer.html
Integer (Java Platform SE 7 )
The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string. In other words, this method returns an Integer object equal to the value of: ... NumberFormatException - if the string cannot be parsed as an integer. ... Returns an Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › Integer.html
Integer (Java SE 11 & JDK 11 )
January 20, 2026 - The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string. In other words, this method returns an Integer object equal to the value of: ... NumberFormatException - if the string cannot be parsed as an integer. ... Returns an Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values.
🌐
Jsparrow
jsparrow.github.io › rules › inefficient-constructor.html
Replace Inefficient Constructors with valueOf() | jSparrow Documentation
All calls to a constructor of a primitive type will be replaced by the corresponding static 'valueOf()' method. For example 'new Integer(
🌐
Demmel
demmel.com › joc › help › JavaDocumentation › java › lang › Integer › Integer.htm
Constructor java.lang.Integer
Package java.lang Class Integer · Integer(int value) Integer(String s) Throws: NumberFormatException · _INSERT_METHOD_SIGNATURE_HERE_ Description: constructor Integer(int value): This constructs a newly allocated Integer object that represents the specified int value.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-integer-class-java
Java.lang.Integer class in Java - GeeksforGeeks
June 21, 2022 - Java Collection · Last Updated ... class can hold a single int value. Constructors: Integer(int b): Creates an Integer object initialized with the value provided....
🌐
Oracle
docs.oracle.com › javase › › 9 › docs › api › java › lang › Integer.html
Integer (Java SE 9 & JDK 9 )
The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string. In other words, this method returns an Integer object equal to the value of: ... NumberFormatException - if the string cannot be parsed as an integer. ... Returns an Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values.
🌐
Reddit
reddit.com › r/java › jdk 9 deprecates number constructors, e.g. integer(int)
r/java on Reddit: JDK 9 deprecates Number constructors, e.g. Integer(int)
September 16, 2016 - Java 9 is expanding the @Deprecated ... getting more aggressive in this area. ... There're both of two constructors, viz: Integer(int value) and Integer(String s) ......
🌐
Coderanch
coderanch.com › t › 773726 › java › replace-statement-deprecated-constructor
Should I replace a statement with a deprecated constructor? (Java in General forum at Coderanch)
June 28, 2023 - "The constructor Integer(int) has been deprecated since version 9 and marked for removal"·. While it still works, is it going to work in the future?
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Integer Java Class Example - Java Code Geeks
May 31, 2021 - The first one constructs a newly allocated Integer object that represents the specified int value. ... There is another constructor which takes String as a parameter. It constructs a newly allocated Integer object that represents the int value ...
🌐
Java
download.java.net › java › early_access › valhalla › docs › api › java.base › java › lang › Integer.html
Integer (Java SE 23 & JDK 23 [build 1])
Returns an Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently ...