StringBuilder
represents a changeable
String
. It provides the operations required to modify the
StringBuilder
, including insert, replace, delete, append, and reverse. It like
StringBuffer
, but is not synchronized. It is ideal for use when it is known that the object will only be used from a single thread.
StringBuilder
s are variable-length in nature, so even if you initialize them to a certain size, they can still grow larger than that. Capacity indicates the number of characters the StringBuilder
can have in it before it has to grow (growing the char array is an expensive operation involving new
).
Incidentally, compilers often implement the String operator "+" by using a StringBuilder
operation:
a + b
is the same as
new StringBuilder().append(a).append(b).toString()
.
Classpath's StringBuilder is capable of sharing memory with Strings for efficiency. This will help when a StringBuilder is converted to a String and the StringBuilder is not changed after that (quite common when performing string concatenation).
@author Paul Fisher
@author John Keiser
@author Tom Tromey
@author Eric Blake ebb9-at-email.byu.edu
@see String
@see StringBuffer
@since 1.5