Java Reference
In-Depth Information
This code creates just one
StringBuilder
object to hold the construction,
appends stuff to it, and then uses
toString
to create a
String
from the
result.
To build and modify a string, you probably want to use the
StringBuilder
class.
StringBuilder
provides the following constructors:
public
StringBuilder()
Constructs a
StringBuilder
with an initial value of
""
(an empty
string) and a capacity of 16.
public
StringBuilder(int capacity)
Constructs a
StringBuilder
with an initial value of
""
and the
given capacity.
public
StringBuilder(String str)
Constructs a
StringBuilder
with an initial value copied from
str
.
public
StringBuilder(CharSequence seq)
Constructs a
StringBuilder
with an initial value copied from
seq
.
StringBuilder
is similar to
String
, and it supports many methods that
have the same names and contracts as some
String
methods
indexOf
,
lastIndexof
,
replace
,
substring
. However,
StringBuilder
does not extend
String
nor
vice
versa.
They
are
independent
implementations
of
CharSequence
.