|
|
The java.lang Package Certification - String Immutability
- String objects are read-only or immutable ie the contents of a String object never change
String str = "Hello";
str = "Goodbye";
- in the above example, the second assignment of "Goodbye" to String, what actually happens is that a new string "Goodbye" is created and the object reference of the new string is stored in the variable str
- operations that seem to modify a String object actually create new read-only String objects; leaving the original object unchanged
- the StringBuffer class provides mutable or flexible string handling
Also see
String literals
|