🌐
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.
🌐
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
Discussions

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
Why can't you make ArrayLists of primitive types...and why can you "cheat" around the restriction by using the wrapper classes?
If you want exactly this (List of primitives) there are few libraries that offer it. These collections are faster and with lower memory footprint, but there is real advantage to use them when your collections are huge. HPPC Trove COLT ... More on reddit.com
🌐 r/javahelp
10
1
April 15, 2018
Java Database Wrapper

If you search for "java jdbc simple DAO" you might be able to borrow some ideas from that. You can blow allot of time with it though so I would set a time limit on how much your research.

I am assuming your are using jdbc. One thing that might be useful is to test database calls outside of the web app so you get all the bugs out first before using it in a web app. ie make a simple java Application using your database classes to call the database directly.

More on reddit.com
🌐 r/javahelp
3
3
October 5, 2016
🌐
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: " + ...
🌐
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....
🌐
Baeldung
baeldung.com › home › java › core java › wrapper classes in java
Wrapper Classes in Java | Baeldung
March 17, 2024 - Well, we can either use constructor or static factory methods to convert a primitive value to an object of a wrapper class. As of Java 9, however, constructors for many boxed primitives such as Integer or Long have been deprecated. So it’s highly recommended to only use the factory methods on new code. Let’s see an example of converting an int value to an Integer object in Java:
🌐
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.
🌐
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.
Find elsewhere
🌐
Scientech Easy
scientecheasy.com › home › blog › wrapper classes in java (with examples)
Wrapper Classes in Java (with Examples) - Scientech Easy
February 3, 2025 - To store double values in an ArrayList, we use an ArrayList<Double>. Example 1: Let’s write a Java program where we will convert a primitive data type int value into an Integer object explicitly.
🌐
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.
🌐
Study.com
study.com › business courses › java programming tutorial & training
Wrapper Classes in Java: Definition & Example - Lesson | Study.com
January 5, 2018 - In the following example, the user entered 7, but it was parsed as a string. To convert to the integer 7, the Integer wrapper class uses the valueOf method: We can also go the other way and convert our new integer value back to a string.
🌐
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.
🌐
Javatpoint
javatpoint.com › wrapper-class-in-java
Wrapper class in Java
May 29, 2014 - Wrapper class in Java with concepts and examples of Byte class, Short class, Integer class, Long class, Float class, Double class, Boolean class and Character class.
🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
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....
🌐
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…