I'm curious just how clever HotSpot is about optimising StringBuilder,
Here are some possible optimisations.
1. when allocating the StringBuilder, compute the length where
possible to create the exact size.
2. when doing append ( "xxx");
append ("yyy");
convert that to append( "xxxyyy");
3. when doing toString, if char[] internally is the correct length,
steal that array to use in the string, and lazily make a copy (which
should be rarely needed.)
4. convert append ( " " ) to append ( ' ' );
5 convert append ( a + b + c ) to append (a ); append (b); append
(c);
If it is not clever, then consider how you might implement these with
a BYTE CODE optimiser.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com