+ 1

Why string is immutable in java?

7th Apr 2020, 3:24 AM
Jagadeesh
Jagadeesh - avatar
1 Answer
+ 3
The key benefits of keeping strings as immutable are caching, security, synchronization, and performance. The String is the most widely used data structure. Caching the String literals and reusing them saves a lot of heap space because different String variables refer to the same object in the String pool. It is also more secure, since they wont be modified.
7th Apr 2020, 3:41 AM
Fernando Pozzetti
Fernando Pozzetti - avatar