The question is very simple, why are strings immutable? Or rather: Why are strings not mutable? As far as I know this only happens in Python and Java...
The question is very simple, why are strings immutable? Or rather: Why are strings not mutable? As far as I know this only happens in Python and Java...
The String class/type is immutable in Java, C#, Javascript, Python, Go... and is a design decision.
It has several advantages:
It has some cons:
It is generally accepted that the advantages outweigh the disadvantages, which is why most modern languages tend to create immutable types for texts.