🌐
W3Schools
w3schools.com › java › java_wrapper_classes.asp
Java Wrapper Classes
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects.
🌐
W3Schools
w3schoolsua.github.io › java › java_wrapper_classes_en.html
Java Wrapper Classes. Lessons for beginners. W3Schools in English
The table below shows the primitive type and the equivalent wrapper class: 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 ...
Discussions

Wrapper Classes Discussion
Read Effective Java 3rd Edition by Joshua Bloch, Item 68 for a full discussion. Joshua recommends to prefer primitives over boxed primitives. A few points he makes: *Primitives are more time and space-efficient. *Double equals operator can't be used with Boxed primitives. *Unboxing can result in a NPE. Auto-unboxing happens automatically, for example, when primitives and boxed primitives are mixed in an operation. More on reddit.com
🌐 r/learnjava
11
8
September 20, 2022
Why use Wrapper Classes over Primitive Datatypes?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
5
4
February 4, 2023
Example for Wrapper Classes

Keep in mind that there is overlap between design patterns and sometimes not everyone agrees on what an implementation looks like. That being said, I would say that a wrapper encloses some class and allows that class to work with some protocol or interface that it originally did not accommodate.

class Ice-T {

sing() {... }

act() { ... }

compose() { ... }

};

But now we have our class in production and we suddenly want it to do the things it already does but in China, where the laws are different. So, we create a wrapper class that encloses our Ice-T class and enforces Chinese laws before permitting calls to sing(), act(), and compose().

class RapperWrapper()

private Ice-T iceT;

void checkAndSing();

void checkAndAct();

void checkAndCompose();

};

But, wait, why don't we just add the logic to our original class and be done with it? Well, we want to maintain separation of concerns. Our wrapper class doesn't know how to sing but it does know how to make sure that Chinese law are complied with before singing is permitted. Also, our original class is already in production and we can't change it: perhaps we're not even allowed to change it because someone else provides it to us.

More on reddit.com
🌐 r/javahelp
3
2
July 16, 2021
I don't understand wrapper classes
Integer b = new Integer(8);
b=b+1;
System.out.println(b);

here I added 1 to b and I got 9 on the console, I could change the Integer object within the main method

You're not actually "changing" the Integer object here. What you're doing is creating a new Integer, with a value of 9, and then storing it in the b variable, throwing away the old object which had the value 8.

i.e. you're changing the variable to point to a new object, rather than modifying the object in-place.

Modifying / mutating the original object would look something like this - it's not something valid which you can do:

Integer b = new Integer(8);
b.increaseBy(1);
System.out.println(b);

The difference is subtle, but it also explains why the code in 'main' couldn't "see" the changes made in the 'add' method.

I also used valueOf and parseInt methods, valueOf method returns an Integer object but I assigned an int primitive type to it and it worked. Similarly, I declared an Integer object and assigned it to the result of parseInt method which returns a primitive type and it also worked.

Basically Java will automatically convert between Integer and int for you, based on what's required in any given context.

This is called "automatic boxing / unboxing".

The main reason Integer exists is:

  • It's possible to have a 'null' Integer, but not a null int - if you want to allow a null value, you need to use the object wrapper type

  • Collections like List, Set, Map etc do not support primitive types, only objects - so these object wrapper / boxed versions need to exist to allow you to store primitive values in collections

More on reddit.com
🌐 r/javahelp
5
1
November 15, 2023
🌐
W3Schools
localdev.w3schools.com › java › java_wrapper_classes.asp
Java Wrapper Classes
abstract boolean break byte case catch char class continue default do double else enum extends final finally float for if implements import instanceof int interface long new package private protected public return short static super switch this throw throws try void while Java String Methods Java Math Methods · Java Examples Java Compiler Java Exercises Java Quiz Java Certificate ... Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects.
🌐
Programiz
programiz.com › java-programming › wrapper
Java Wrapper Class (With Examples)
class Main { public static void main(String[] args) { // creates objects of wrapper class Integer aObj = Integer.valueOf(23); Double bObj = Double.valueOf(5.55); // converts into primitive types int a = aObj.intValue(); double b = bObj.doubleValue(); System.out.println("The value of a: " + ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › wrapper-classes-java
Wrapper Classes in Java - GeeksforGeeks
Java provides wrapper classes for all eight primitive data types to support object-based operations. Example: Converting Primitive to Wrapper (Autoboxing)
Published   April 6, 2026
🌐
W3Schools
w3schools.com › java › exercise.asp
Exercise: - JAVA Wrapper Classes
Wrapper Classes4 q · Regular Expressions5 q · Threads3 q · Lambda Expressions4 q · Advanced Sorting3 q by w3schools.com · Next Question » · Try Again · You have already completed these exercises! Do you want to take them again? Yes No · × · Close the exercise · You completed the JAVA Wrapper Classes Exercises from W3Schools.com ·
🌐
W3Resource
w3resource.com › java-tutorial › java-wrapper-classes.php
Java Wrapper Classes - w3resource
August 19, 2022 - Below table lists wrapper classes in Java API with constructor details. ... As explain in above table all wrapper classes (except Character) take String as argument constructor. Please note we might get NumberFormatException if we try to assign invalid argument in the constructor. For example to create Integer object we can have the following syntax.
🌐
Tutorialspoint
tutorialspoint.com › java › java_wrapper_classes.htm
Java - Wrapper Classes
In Java, to create a wrapper object, ... objects, just print the object. ... In this example, we've showcase use of primitives and their operations using a wrapper class....
Find elsewhere
🌐
Medium
medium.com › @priyaiotacademy122_2106 › java-wrapper-class-explained-key-applications-and-example-abe44d483967
Java Wrapper Class Explained — Key Applications and Example | by priyankayadav | Medium
February 25, 2025 - With wrapper classes, you can easily store simple types in collections, use features that automatically convert between types, and access useful methods. So in this article, we will explain what they are, and how they are used. As well as give simple examples to help you understand better. A Java Wrapper Class is a special type of class that takes a basic data type and turns it into an object.
🌐
BeginnersBook
beginnersbook.com › 2017 › 09 › wrapper-class-in-java
Wrapper class in Java
November 8, 2022 - For example: While working with collections in Java, we use generics for type safety like this: ArrayList<Integer> instead of this ArrayList<int>. The Integer is a wrapper class of int primitive type. We use wrapper class in this case because generics needs objects not primitives.
🌐
Baeldung
baeldung.com › home › software architecture › what is a wrapper class?
What Is a Wrapper Class? | Baeldung on Computer Science
May 16, 2024 - The Integer class wraps the primitive data type int, as an example. Conversion from the primitive data type to the wrapper class and the opposite are easy using boxing and unboxing, respectively.
🌐
Hero Vired
herovired.com › learning-hub › blogs › wrapper-class-in-java
What is Wrapper Classes in Java: Types, Define, example
January 21, 2025 - Wrapper classes are a fundamental concept in Java. They provide an easy way to interact with primitive data types, such as ints and doubles, and allow developers to use objects rather than primitives. In this article, we’ll demystify the concept of wrapper classes in Java and explore how they can be used effectively in programming applications.
🌐
Scaler
scaler.com › home › topics › java › wrapper classes in java
Wrapper Classes in Java - Scaler Topics
April 27, 2024 - We can also create a custom Wrapper class in Java, which wraps a primitive data type. ... A: An example of a wrapper in Java is the Integer class, which wraps the primitive data type int to provide additional functionality.
🌐
PrepBytes
prepbytes.com › home › java › wrapper class in java
Wrapper Class in Java Explanation with Examples
October 16, 2023 - In this article, we’ll explore the concept of wrapper classes in Java. We’ll discuss why and when you should use wrapper classes, how to create instances of wrapper classes, and the various methods they provide for converting between primitive types and objects.
🌐
Study.com
study.com › business courses › java programming tutorial & training
Wrapper Classes in Java: Definition & Example - Lesson | Study.com
January 5, 2018 - The wrapper class for the int data type is the Integer class. Let's expand upon the previous example of the Integer and use one of the methods to convert it to a Double. The method to do this is doubleValue(), and the code looks like: Now that ...
🌐
Medium
medium.com › @TechiesSpot › wrapper-classes-in-java-when-and-how-to-use-them-bf50b83a9b7b
Wrapper Classes in Java: When and How to Use Them | by Techie's Spot | Medium
October 31, 2023 - In Java, wrapper classes play a crucial role in dealing with primitive data types as objects. They wrap primitive values into objects, allowing you to perform various operations that are otherwise not possible with primitives. In this article, we’ll explore the concept of wrapper classes, understand why they are needed, differentiate them from data types, provide code examples, discuss best practices, recommend books for further learning, and highlight some commonly used functions in wrapper classes.
🌐
Medium
medium.com › @gaddamnaveen192 › everything-you-need-to-know-about-wrapper-classes-in-java-9b30cca51e6c
Everything You Need to Know About Wrapper Classes in Java | by Gaddam.Naveen | Medium
June 13, 2025 - That's why we need wrapper classes — to wrap primitive values into object form so they can be used where only objects are allowed. For example, the primitive type int has a wrapper class called Integer.
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › what is wrapper class in java?
What is Wrapper Class in Java? - Shiksha Online
October 12, 2023 - Let us see a Java program below to understand Unboxing: ... In the above code, char x= ch is converting the character object to primitive conversion and int num method returns the integer object finally because of unboxing.