+ 2

Why strings are immutable in java??

this is already known question but i want more clarity with examples...

29th May 2017, 5:55 PM
Rama krishna
Rama krishna - avatar
3 ответов
27th Jan 2018, 7:36 PM
ASIF BILAKHIYA
ASIF BILAKHIYA - avatar
+ 2
it means that, once we create a string object, we can't perform any changes in the existing object, if we are trying to change a new object will create. Is that same or what? so this feature is called immutable or what?
31st May 2017, 9:39 AM
Rama krishna
Rama krishna - avatar
+ 1
Principally for caching and security reason. For first imagine two string with same value, with string collector pool we need only one object for storing them. The second concern variable that value must can't change at runtime. Imagine a string to dB connection or network URL. Another important things: don't use -> new String("bad"); use this one -> String s = "well done";
30th May 2017, 9:59 PM
Federico Viceconti
Federico Viceconti - avatar