I'm looking to better my understanding of Strings. The way they operate often seems unintuitive to me, and I'm wondering what the logic/ rationale is on why they work like they do. Some examples:
1) Immutability - Often, I would like to change an individual char of a String, but this requires either creating a new String, or converting the String to some other mutable object and converting it back. If String were mutable, this could be done much faster (both in terms of writing the code and executing it). Why are they immutable?
2) Concatenation - String concatenation is expensive, because it requires a brand-new String to be created, rather than modifying the current String. Why not allow a String to dynamically resize as ArrayLists do and skip this wasted time?
3) Typing (Java) - As I understand it, Strings are not a primitive type, but seem to behave like one. Why is this?