However, wrapper classes represent primitive types, and primitive types (except String) are mutable.

Firstly, String isn't a primitive type.

Secondly, it makes no sense to talk about the primitive types being mutable. If you change the value of a variable like this:

int x = 5;
x = 6;

That's not changing the number 5 - it's changing the value of x.

While the wrapper types could have been made mutable, it would have been annoying to do so, in my view. I frequently use readonly collections of these types, and wouldn't want them to be changeable. Very occasionally I want a mutable equivalent, but in that case it's easy enough to come up with one, or use the Atomic* classes.

I find myself wishing that Date and Calendar were immutable far more often than I find myself wanting Integer to be mutable... (Of course I normally reach for Joda Time instead, but one of the benefits of Joda Time is immutability.)

Answer from Jon Skeet on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ primitive-wrapper-classes-are-immutable-in-java
Primitive Wrapper Classes are Immutable in Java - GeeksforGeeks
August 30, 2022 - It is because all primitive wrapper classes (Integer, Byte, Long, Float, Double, Character, Boolean, and Short) are immutable in Java, so operations like addition and subtraction create a new object and not modify the old.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 670745 โ€บ java โ€บ Wrapper-Classes-Immutable
Why Wrapper Classes are Immutable [Solved] (Java in General forum at Coderanch)
I guess he means the standard wrapper classes for primitives: java.lang.Integer, java.lang.Long, etc., and yes, they are immutable.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ primitive-wrapper-classes-are-immutable-in-java
Primitive Wrapper Classes are Immutable in Java
The references to the immutable objects can be easily shared or cached without having to copy or clone them as there state can not be changed ever after construction. The best use of the wrapper class as immutable objects is as the keys of a map.
๐ŸŒ
Trinket
books.trinket.io โ€บ thinkjava2 โ€บ chapter9.html
Immutable Objects | Think Java | Trinket
Like strings, objects from wrapper classes are immutable, and you have to use the equals method to compare them:
๐ŸŒ
Quora
quora.com โ€บ What-are-the-advantages-that-all-of-the-wrapper-classs-objects-are-immutable-e-g-String-Integers-objects-but-many-other-objects-are-mutable-in-Java
What are the advantages that all of the wrapper class's objects are immutable (e.g. String Integer's objects), but many other objects are mutable in Java? - Quora
Answer (1 of 2): Well in short the answer is every Java wrapper class gives you a method to convert it to String. But guess what cast a primitive int to a string and follow the class cast exception. Since the String class is immutable and can be used as key for all the map implementation so are...
๐ŸŒ
Nus-cs2030s
nus-cs2030s.github.io โ€บ 2021-s2 โ€บ 16-wrapper.html
16. Wrapper Class - CS2030S Programming Methodology II
The second one can be about 2 times faster. All primitive wrapper class objects are immutable -- once you create an object, it cannot be changed. Thus, every time the sum in the first example above is updated, a new Double object gets created.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @sandeep_maurya โ€บ are-wrapper-classes-immutable-in-java-explanation-with-an-example-51693ad0ecfc
Are Wrapper Classes Immutable in Java? Explanation with an Example | by Sandeep Maurya | Medium
March 11, 2025 - In Java, wrapper classes (like Integer, Double, Boolean, Character, etc.) are indeed immutable. This means that once an instance of aโ€ฆ
๐ŸŒ
Nus-cs2030s
nus-cs2030s.github.io โ€บ 2425-s1 โ€บ 19-wrapper.html
19. Wrapper Class - CS2030S Programming Methodology II
All primitive wrapper class objects are immutable -- once you create an object, it cannot be changed.
๐ŸŒ
Oracle
forums.oracle.com โ€บ ords โ€บ apexds โ€บ post โ€บ java-wrapper-classes-are-immutable-8673
Java Wrapper Classes are immutable? - Oracle Forums
October 15, 2011 - Hi guys, The one artichle i have read it says wrapper classes are immutable and once you assign a value to a variable(wrapper class type) you wont be able to change that value ,also ; Integer myInt=...
๐ŸŒ
The IoT Academy
theiotacademy.co โ€บ home โ€บ explain java wrapper classes with examples โ€“ beginners guide
Explain Java Wrapper Classes with Examples - Beginners Guide - Tech & Career Blogs
June 16, 2025 - Since Java 5, there is no longer a need to transform primitives into objects using the wrapper classes' valueOf() method. An object is immutable when its state doesn't change after initialization.
๐ŸŒ
Medium
medium.com โ€บ coderbyte โ€บ how-to-create-immutable-classes-in-java-c59250e1b6a7
How to Create Immutable Classes in Java | by shivam bhatele | Tech x Talent | Medium
April 24, 2022 - So, as you can see, a new instance was created that holds the literal โ€œInterviewBit Scalerโ€ and then the reference s1 stores the address of this new literal now. Hence, the old instance/object is immutable whereas the reference is mutable. This is why we can change the values of the Strings and Wrapper classes and yet call them Immutable Classes. There are two sides to every coin.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 684075 โ€บ java โ€บ Wrapper-classes-immutable
Wrapper classes are immutable (Beginning Java forum at Coderanch)
August 31, 2017 - However you can see it by using hashcode() and because both that objects are different so hashcode() comes out to be different. Relate the Wrapper Classes with String class. Since String class is also immutable means any changes make then a new String object gets created.
๐ŸŒ
Movie Cultists
moviecultists.com โ€บ are-wrapper-classes-immutable
Are wrapper classes immutable?
All primitive wrapper classes (Integer, Byte, Long, Float, Double, Character, Boolean and Short) are immutable in Java, so operations like addition and subtraction
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2127730 โ€บ are-wrapper-objects-really-immutable
Are Wrapper objects really immutable? | Sololearn: Learn to code for FREE!
January 9, 2020 - see this how to create our own ... Objects of wrapper class are immutable means state of object won't be changed however the reference that points to object can be reassigned....
Top answer
1 of 4
24

Any type which doesn't give you any means to change the data within it is immutable - it's as simple as that. Yes, all the primitive wrapper types are immutable1, as is String. UUID, URL and URI are other examples.

Although Calendar and Date in the built-in Java API are mutable, many of the types within Joda Time are immutable - and to my mind, this is one reason why Joda Time is easier to work with. If an object is immutable, you can keep a reference to it somewhere else in your code and not have to worry about whether or not some other piece of code is going to make changes - it's easier to reason about your code.


1 by which I mean java.lang.Integer etc. As noted elsewhere, the Atomic* classes are mutable, and indeed have to be in order to serve their purpose. There's a difference in my mind between "the standard set of primitive wrapper classes" and "the set of classes which wrap primitive values".

You can write your own mutable wrapper class very easily:

public class MutableInteger
{
    private int value;

    public MutableInteger(int value) 
    {
         this.value = value;
    }

    public int getValue()
    {
        return value;
    }

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

So as you can see, there's nothing inherently immutable about wrapper classes - it's just that the standard ones were designed to be immutable, by virtue of not providing any way to change the wrapped value.

Note that this allows for the same object to be used repeatedly when boxing, for common values:

Integer x = 100;
Integer y = 100;
// x and y are actually guaranteed to refer to the same object

Integer a = 1000;
Integer b = 1000;
// a and b *could* refer to the same object, but probably won't
2 of 4
11

Before Java 5, all the primitive wrapper classes were immutable.

However, the atomic wrapper classes introduced in Java 5 (AtomicInteger, AtomicLong, AtomicBoolean and AtomicReference<V>) are mutable.

๐ŸŒ
MyRubyLearning
myrubylearning.wordpress.com โ€บ 2013 โ€บ 11 โ€บ 18 โ€บ why-wrapper-class-is-immutable
why wrapper class is immutable | MyRubyLearning
November 18, 2013 - No. String is an immutable class in java because we can not change the value of any string object. In Java, a wrapper class is nothing but a class in which a primitive type value is wrapped up.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjava โ€บ wrapper classes discussion
r/learnjava on Reddit: Wrapper Classes Discussion
September 20, 2022 -

The way I understand wrapper classes is they are used to convert primitive data types into objects so you can store them in Collection classes. I also believe that this happens automatically on backend by the compiler through a process called autoboxing.

To me, someone with no real world programming experience, I find myself wondering why use primitives at all?

The wrapper classes are much more interesting because you get methods to do things, where primitives are boring. Why not just use wrapper classes for everything? Is that even possible?

My gut tells me that someone is going to say primitives are faster, but is that a valid argument considering the speed of computers today?