String manipulation HOME BACK String manipulation Strings in Java are immutable. This means that once you created a String you can never change it's value. It's address is assigned to s1.
String concatenation has a similar effect.
In other words, any action that alters content of a string object will result in creation of one or more objects, some of them temporary. This brings us the to the conclusion that it not very smart to append strings in tight loops as it will result in a huge number of temporary objects created and discarded. More over, because of immutability of strings in Java it does not seem possible to pool string objects. One solution to this is to use StringBuffer class for string content manipulation instead of String class.