How to prove string is immutable in java

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

First I would like to appreciate this kind of video.
Your example giving a chance to confusion between object reference and immutability.

radhakrishnansivaramakrish
Автор

How about the string created using new .. is that also immutable?

nagarajanerode
Автор

String s1 = "abc";
String s2 = s1;
s1 = "def";

Since String is immutable, Changing 's1' doesn't effect 's2'.

sanalsz