Why string is immutable in java?

2.22K viewsJava
0

Why string is immutable in java?

Posted new comment

[…] 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.

 

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