๐ŸŒ
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.
๐ŸŒ
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.
Discussions

java - how to create wrapper class for any user defined class - Stack Overflow
Anyways, do you mean you want the Java program to be creating wrapper classes on-the-fly, at runtime? Or do you mean that as part of the program you're writing you want to write some wrapper classes? ... @QuantumMechanic yaa! i want to create it as a part of program but i don't have any idea from where to start?? :( ... Question does not make sense. What is a "wrapper" class for a "user-defined" class? Do you have an example ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
Any reason to use a class instead of a primitive when declaring fields?
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 - best also formatted as code block 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. 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/markdown editor: 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/learnjava
7
13
September 8, 2023
๐ŸŒ
Scientech Easy
scientecheasy.com โ€บ home โ€บ blog โ€บ wrapper classes in java (with examples)
Wrapper Classes in Java (with Examples) - Scientech Easy
February 3, 2025 - For example, if we create an object of Integer wrapper class, it contains a single variable (or field) that will store an int value like 25, as shown in the below figure. Thus, Integer is a wrapper class of int data type.
๐ŸŒ
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
๐ŸŒ
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: " + ...
๐ŸŒ
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.
Top answer
1 of 3
15

The term 'wrapping' sometimes means the same thing as encapsulation, where an object or type is used internally by a class as part of its implementation details, and doesn't expose it to outside code. However, wrapping often refers specifically to the act of encapsulating a class in another class which implements the same interface as the wrapped class but changes its behaviour slightly or adds new features (Decorator Pattern), or the outer class implements a different interface, essentially converting the wrapped class to make it compatible with another program (Adapter Pattern). Both of these types of wrapping are nearly always done manually, and must be done at compile-time (by writing code).

You can also generate dynamic proxies for virtually any object at runtime using java.lang.reflect.Proxy.newProxyInstance(...). You can read the official guide on Dynamic Proxy Classes to learn how to use it. However, you haven't given any use cases yet, so this might not be what you're looking for. Proxies are usually reserved for protecting objects or delegating to a remote server via RPC, and can be very complex.

2 of 3
0

Sample code for creating wrapper :

import java.util.ArrayList;
import java.util.List;


class IntVal {
    private int i;
    public IntVal(int a) {
        i = a;
    }

    public int getVal() {
        return i;
    }

    public void setValue(int a) {
        this.i = a;
    }

    public void increment() {
        i++;
    }

    @Override
    public String toString() {
        return Integer.toString(i);
    }
}

public class WrapperClass {

    public static void main(String[] args) {



  List list = new ArrayList();

  for (int i = 0; i < 10; i++) {
      list.add(new IntVal(i)); 
  }
  System.out.println(list);
  for (int i = 0; i < list.size(); i++) {
      ((IntVal) list.get(i)).increment();
  }

  System.out.println(list);

    }
}
Find elsewhere
๐ŸŒ
Geekster
geekster.in โ€บ home โ€บ wrapper classes in java
Java Wrapper Classes (with Example)
June 27, 2024 - Type conversions: Wrapper classes provide methods to convert between primitive types and objects. For example, Integer.parseInt() converts a string to an int, and Integer.toString() converts an Integer object to a string.
๐ŸŒ
Great Learning
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ java wrapper classes with examples
Java Wrapper Classes with Examples
June 18, 2025 - Learn about Java Wrapper Classes in this tutorial. Understand how to convert primitive types into objects, explore key methods, and see practical examples of using classes like Integer, Double, and more.
๐ŸŒ
Oodlestechnologies
oodlestechnologies.com โ€บ blogs โ€บ what-are-wrapper-classes-and-why-we-use-in-java
What are Wrapper Classes and why we use in java
February 14, 2020 - these all methods are static methods which will call with the class name these methods are used to convert Object to respective primitive data type. all methods will be available in wrapper classes because wrapper class derived from number class. how to use these methods:- Example ... import java.io.*; class DemoWrapper { public static void main(String arg[]) throws IOException{ System.out.println("enter some inter value"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); //receive data from keyword in string form String data=br.readLine(); // convert to integer int i=In
๐ŸŒ
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 also provide a way to handle Exceptions in Java. For example, the Integer wrapper class provides the parseInt() method, which is used to parse an int from a String.
๐ŸŒ
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....
๐ŸŒ
The Knowledge Academy
theknowledgeacademy.com โ€บ blog โ€บ wrapper-class-in-java
Wrapper Class in Java and How to Create a Custom Wrapper Class
December 11, 2025 - Java provides these classes to ... (e.g., ArrayList, HashMap in Java). For example, the wrapper class for the int primitive is Integer, and for float, it's Float....
๐ŸŒ
TechVidvan
techvidvan.com โ€บ tutorials โ€บ java-wrapper-class
Wrapper Class in Java - Learn Autoboxing & Unboxing with Coding Examples - TechVidvan
March 16, 2020 - The process to automatically convert the primitive data types into corresponding wrapper class objects is called Autoboxing in Java. This is Autoboxing because this is done automatically by the Java compiler. For example, char to Character, int to Integer, long to Long, double to Double, float to Float, boolean to Boolean, byte to Byte, and short to Short.
๐ŸŒ
Medium
medium.com โ€บ @gauravshah97 โ€บ wrapper-classes-in-java-0c5d9205f3b3
Wrapper Classes in Java
April 26, 2024 - Wrapper Classes in Java Introduction Java defines a wrapper class for each of its primitive data types. A Wrapper class in Java is one whose object wraps or contains primitive data types. Wrapper โ€ฆ
๐ŸŒ
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.
๐ŸŒ
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 โ€บ java โ€บ core java โ€บ wrapper classes in java
Wrapper Classes in Java | Baeldung
March 17, 2024 - Basically, if we write a method that accepts a primitive value or wrapper object, we can still pass both values to them. Java will take care of passing the right type e.g. primitive or wrapper depending upon context. In this quick tutorial, we talked about wrapper classes in Java, as well as the mechanism of autoboxing and unboxing.
๐ŸŒ
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 - For example, if you have a database field that can be null, using a wrapper class like Integer allows you to represent that state, whereas a primitive int cannot be null. Each wrapper class in Java comes with a set of methods that can be utilized ...