When a StringBuffer is turned into a String, the new String
uses the StringBuffer's backing array. This is a very fast
way to create the String since no allocation is necessary
but it can waste space since the backing array may be much
larger than the resulting String. Reusing StringBuffers can
make this problem worse since the StringBuffer may have grown
its backing array in past usages.
We would like to give users a method to use if they feel that
the efficient use of memory is more important than the speed that
toString currently has. Adding a compact method in StringBuffer
would allow a user to eliminate the wasted memory by causing the
backing array to be resized to fit the length of the StringBuffer.
The idiom buffer.compact().toString() will result in a String
with a backing array of the minimum size required.