Originally posted by Jethram Boda:
Diff between string and string buffer
//immutable
String s1 = "s1";
s1.concat(" - s1");
//new string created. " - s1" is NOT appended to original s1 value - a
//new value is created in memory for which you have no reference to.
System.out.println(s1); //only print s1
//mutable, value can be changed
StringBuffer s2 = new StringBuffer("s2");
s2.append(" - s2");
//s2 is actually appended here with " - s2" and still
// referenced by s2 variable
System.out.println(s2); //prints "s2 - s2"