Junior — Middle
Can the content of a String object be changed after it is created?
sobes.tech AI
Answer from AI
In Java, objects of the String class are immutable. This means that once a string is created, its contents cannot be changed. Any operations that seem to modify the string (for example, concatenation) actually create a new String object.
Example:
String s = "Hello";
s = s + " World"; // a new String object with the content "Hello World" is created
If a mutable string is needed, classes like StringBuilder or StringBuffer are used.