[concurrency-interest] Why String is immutable?

Gregg Wonderly gregg at cytetech.com
Wed Sep 14 08:43:00 EDT 2005



Bharath Ganesh wrote:
> Hi
>  
> Could anyone tell me why String is immutable?

There are several reasons, but the one that generally has the largest impact is, so that a single instance of any string 
value can be used for all references.  Look at String.intern(), which is used to maintain a "weak hash map" of all 
string values. This greatly reduces the total space for String values in many applications.  It would be interesting,
to have the ability to turn that off, and then see the difference in heap use for an XML based application for instance.

Gregg Wonderly


More information about the Concurrency-interest mailing list