|
The StringBuffer Myth
|
Arno Huetter
|
Jan 16, 2003 11:03 PST
|
The StringBuffer Myth - Reopened
What causes the big performance penalty difference of String concatenation
in comparison to StringBuffer is not the number of calls to
StringBuffer.append(), but the StringBuffer's capacity. If the capacity is
exceeded by append(), the internal buffer needs to be re-allocated. The
capacity can be changed programmatically, by passing the expected length (or
somewhat more) to the StringBuffer constructor. The default StringBuffer
constructor (as employed when concatenating Strings with +) defines a
capacity of 16 - too few in most of the cases.
Kind regards,
Arno Huetter
|
|
 |
|