When we say immutable, we mean the object cannot be changed. For instance, if I have the below code
Now we have created a
String object with the value "Bacon is delicious". When we try to add " and nutritious!" to that object....well, we can't. Strings are immutable. So
Java actually creates a whole new object, with the value "Bacon is delicious and nutritious!" and assigns it to
test. The original String object containing "Bacon is delicious" still exists, we just don't have a variable pointing to it.*
*There was also a String object " and nutritious!" created, but String creation is a little off-topic.
SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."