๐ŸŒ
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
๐ŸŒ
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
To wrap a value, call the constructor for the wrapper class in earlier versions of Java. In Java 9 on, this is deprecated which means itโ€™s not the best way to do this anymore, and you should instead just set it equal to a value. The AP CSA Exam covers Java 7 which does allow using the constructor.
๐ŸŒ
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.
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ wrapper
Java Wrapper Class (With Examples)
In this tutorial, we will learn about the Java Wrapper class with the help of examples. The wrapper classes in Java are used to convert primitive types (int, char, float, etc) into corresponding objects.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ wrapper-classes-java
Wrapper Classes in Java - GeeksforGeeks
Explanation: Here, the primitive int value is automatically converted into an Integer object by Java. This automatic conversion is called autoboxing. Wrapper classes are required in Java for the following reasons:
Published ย  April 6, 2026
๐ŸŒ
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 ...
๐ŸŒ
W3Schools
w3schoolsua.github.io โ€บ java โ€บ java_wrapper_classes_en.html
Java Wrapper Classes. Lessons for beginners. W3Schools in English
HTML Certificate CSS Certificate ... Certificate XML Certificate ... Wrapper classes provide a way to use primitive data types (int, boolean, etc.) as objects....
๐ŸŒ
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 ...
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
๐ŸŒ
Coding Diary
spongebob53.github.io โ€บ w3schools-wrapper_class
W3schools - Wrapper Class
December 20, 2021 - public class Main{ public static void main(String[] args){ Integer myInt = 5; Double myDouble = 1.2; System.out.print(myInt.intValue()); // output 5 System.out.print(myDouble.doubleValue()); // output 1.2 String myString = myInt.toString(); //another useful method, which is used to convert wrapper objects to strings System.out.print(myString.length()); // output โ€œ5โ€ } } ... ์ด ํŽ˜์ด์ง€๋Š” ๋‹ค์Œ์— ๋Œ€ํ•œ ๊ณต๋ถ€ ๊ธฐ๋ก์ž…๋‹ˆ๋‹ค JAVA(์ž๋ฐ”), Python(ํŒŒ์ด์ฌ) ๊ธฐ๋ฐ˜์˜ AI ํ™œ์šฉ ์‘์šฉ ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ์ž ์–‘์„ฑ ๊ณผ์ • 2021.11.10.
๐ŸŒ
Nus-cs2030s
nus-cs2030s.github.io โ€บ 2324-s2 โ€บ 19-wrapper.html
19. Wrapper Class - CS2030S Programming Methodology II
Java provides wrapper classes for each of its primitive types. 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.
๐ŸŒ
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 ...
๐ŸŒ
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
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. Hereโ€™s an example of unboxing: Integer i = 2; // autoboxing - wrap 2 int number = i; // unboxing - back to primitive type
๐ŸŒ
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 - The Integer class wraps an int, and the Double class wraps a double. Both live in the java.lang package, which is available automatically, so you do not write an import statement to use them.
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2017 โ€บ 09 โ€บ wrapper-class-in-java
Wrapper class in Java
November 8, 2022 - This way we are ensuring that this HashMap keys would be of integer type and values would be of string type. 2. Wrapper class objects allow null values while primitive data type doesnโ€™t allow it. 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); } }
๐ŸŒ
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 | Fiveable
January 5, 2023 - Mastering wrapper classes requires understanding when Java performs these automatic conversions, how to handle null values safely, and the important differences between primitive and object comparison. This knowledge is essential for working with Java collections and avoiding common runtime errors. Major concepts: Integer class constants and methods, autoboxing from primitives to wrapper objects, unboxing from wrapper objects to primitives, valueOf() factory methods for object creation, intValue() for explicit conversion
๐ŸŒ
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.
๐ŸŒ
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....
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ BHSawesome2 โ€บ topic-4-7-wrapper-classes.html
10.2.1 Using wrapper classes with ArrayList
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 ...