Why string is immutable in java?

3.96K viewsJava
0

Why string is immutable in java?

Manohar Posted new comment November 13, 2019

[…] Read : Why string is immutable in java? […]

Add a Comment
1
  1. String pool is possible only because String is immutable in Java.
  2. This way Java Runtime frees a lot of heap space because different String variables can refer to the same string variable in the pool.
  3. If String not have been immutable, then String interning not have been possible because if any variable has changed the value, it has been reflected in the other variables too.

 

Manohar Changed status to publish November 13, 2019
Add a Comment
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.