Whats the difference in the memory allocation for StringBuffers?
The key difference between a String and a StringBuffer in terms of memory allocation is that String objects are immutable; once the string contents are set they cannot be changed, so the virtual machine can optimise memory use on this basis. The content of StringBuffers can be expanded beyond their initial buffer size, so the memory allocation needs to be variable and must be managed by the Java runtime system. The StringBuffer class automatically adjusts its buffer size to fit the string content it is given, but you should instantiate the class with an explicit buffer size large enough to avoid the performance overhead associated with such resizes.