Originally posted by Murthy Kompella:
Is this not against Strings immutability. Please explain.
No. When you use the String concatenation operator, you don't actually change the String. Rather that operator returns a brand new String.
Look at this example:
Obviously, the original String hadn't changed, even after the concatenation operator. If it had, printing the String object referenced by t would have also indicated that change. The concatenation operator creates a new String object, in which both the original contents of the String "Test" and the new String "1" are combined. A reference to that new object is then assigned to s.
I hope that helps,
Corey