Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Why String is Immutable in java?

user-image
Question added by Muhammed Rashik
Date Posted: 2013/03/07
Zaid Rabab'a
by Zaid Rabab'a , Technical Team Lead , ESKADENIA Software

imagine StringPool facility without making string immutable , its not possible at all because in case of string pool one string object/literal e.g.
"Test" has referenced by many reference variables , so if any one of them change the value others will be automatically gets affected i.e.
lets say String A = "Test" String B = "Test" Now String B called "Test".toUpperCase() which change the same object into "TEST" , so A will also be "TEST" which is not desirable.

More Questions Like This