DEV Community

Discussion on: Why String is Immutable in JAVA? What exactly does it mean?

Collapse
 
scottshipp profile image
scottshipp

A couple of minor additional details:

The action of caching Strings in a shared pool is technically called interning string literals where "to intern" means "to cache in a pool that the String class stores internally" and "string literal" means "a unique instance of a String (like "Hello")."

I'm not sure if I am misreading the last line but the reason for interning string literals is explicitly to optimize for safely sharing String values in a given JVM. There should be no possible negative side effects as a result.

JSR 3.10.5 is a great reference for more detail.