Frage im Vorstellungsgespräch bei Dassault Systèmes

Why the strings are immutable in java??

Antworten zu Vorstellungsgespräch

Anonym

11. Okt. 2019

It's because of string literal pool

Anonym

27. Feb. 2020

The string is Immutable in Java because String objects are cached in String pool. ... Another reason of why String class is immutable could die due to HashMap. Since Strings are very popular as HashMap key, it's important for them to be immutable so that they can retrieve the value object which was stored in HashMap.