Immutable String in Java

In java, string objects are immutable. Immutable simply means unmodifiable or unchangeable.

Once string object is created its data or state can’t be changed but a new string object is created.

Let’s try to understand the immutability concept by the example given below:

Why string objects are immutable in java?
Because java uses the concept of string literal. Suppose there are 5 reference variables, all refer to one object “Sachin”.If one reference variable changes the value of the object, it will be affected by all the reference variables. That is why string objects are immutable in java.


Thank you for all your help and assistance over the years with our products.


"My experience at Java E Training is valued and I loved every leaning moment here."

Phone: +91-9640400300
Hyderabad, IN 500032