Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Why String is Immutable in java?

user-image
Question ajoutée par Muhammed Rashik
Date de publication: 2013/03/07
Zaid Rabab'a
par Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.

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