Why String is immutable explain with example?

Trường Phan

New member
Why String is immutable explain with example?
Answer
The string is Immutable in Java
because String objects are cached in the String pool. … At the same time, String was made final so that no one can compromise invariant of String class like Immutability, Caching, hashcode calculation, etc by extending and overriding behaviors.
 

Tìm kiếm

Back
Top