java.lang.Object
|
+--java.lang.StringBuffer
A string buffer implements a mutable sequence of characters. A string buffer is like a
String, but can be modified. At any
point in time it contains some particular sequence of characters, but
the length and content of the sequence can be changed through certain
method calls.
String buffers are safe for use by multiple threads. The methods are synchronized where necessary so that all the operations on any particular instance behave as if they occur in some serial order that is consistent with the order of the method calls made by each of the individual threads involved.
String buffers are used by the compiler to implement the binary
string concatenation operator +. For example, the code:
x = "a" + 4 + "c"
is compiled to the equivalent of:
x = new StringBuffer().append("a").append(4).append("c")
.toString()
which creates a new string buffer (initially empty), appends the string
representation of each operand to the string buffer in turn, and then
converts the contents of the string buffer to a string. Overall, this avoids
creating many temporary strings.
The principal operations on a StringBuffer are the
append and insert methods, which are
overloaded so as to accept data of any type. Each effectively
converts a given datum to a string and then appends or inserts the
characters of that string to the string buffer. The
append method always adds these characters at the end
of the buffer; the insert method adds the characters at
a specified point.
For example, if z refers to a string buffer object
whose current contents are "start", then
the method call z.append("le") would cause the string
buffer to contain "startle", whereas
z.insert(4, "le") would alter the string buffer to
contain "starlet".
In general, if sb refers to an instance of a StringBuffer,
then sb.append(x) has the same effect as
sb.insert(sb.length(), x).
Every string buffer has a capacity. As long as the length of the character sequence contained in the string buffer does not exceed the capacity, it is not necessary to allocate a new internal buffer array. If the internal buffer overflows, it is automatically made larger.
ByteArrayOutputStream,
String, Serialized Form
| Constructor Summary | |
StringBuffer
copy-> new StringBuffer()copy-> <StringBuffer var> = new StringBuffer();
|
|
StringBuffer
copy-> new StringBuffer( )copy-> <StringBuffer var> = new StringBuffer(<int length>);
|
|
StringBuffer
copy-> new StringBuffer( )copy-> <StringBuffer var> = new StringBuffer(<String str>);
|
|
| Method Summary | |
StringBuffer |
append(boolean b)
copy-> .append( )copy-> <StringBuffer var>=<StringBuffer>.append(<boolean b>);
|
StringBuffer |
append(char c)
copy-> .append( )copy-> <StringBuffer var>=<StringBuffer>.append(<char c>);
|
StringBuffer |
append(char[] str)
copy-> .append( )copy-> <StringBuffer var>=<StringBuffer>.append(<char[] str>);
|
StringBuffer |
append(char[] str,
int offset,
int len)
copy-> .append(, , )copy-> <StringBuffer var>=<StringBuffer>.append(<char[] str>, <int offset>, <int len>);
|
StringBuffer |
append(double d)
copy-> .append( )copy-> <StringBuffer var>=<StringBuffer>.append(<double d>);
|
StringBuffer |
append(float f)
copy-> .append( )copy-> <StringBuffer var>=<StringBuffer>.append(<float f>);
|
StringBuffer |
append(int i)
copy-> .append( )copy-> <StringBuffer var>=<StringBuffer>.append(<int i>);
|
StringBuffer |
append(long l)
copy-> .append( )copy-> <StringBuffer var>=<StringBuffer>.append(<long l>);
|
StringBuffer |
append(Object obj)
copy-> .append( )copy-> <StringBuffer var>=<StringBuffer>.append(<Object obj>);
|
StringBuffer |
append(String str)
copy-> .append( )copy-> <StringBuffer var>=<StringBuffer>.append(<String str>);
|
int |
capacity()
copy-> .capacity()copy-> <int var>=<StringBuffer>.capacity();
|
char |
charAt(int index)
copy-> .charAt( )copy-> <char var>=<StringBuffer>.charAt(<int index>);
|
StringBuffer |
delete(int start,
int end)
copy-> .delete(, )copy-> <StringBuffer var>=<StringBuffer>.delete(<int start>, <int end>);
|
StringBuffer |
deleteCharAt(int index)
copy-> .deleteCharAt( )copy-> <StringBuffer var>=<StringBuffer>.deleteCharAt(<int index>);
|
void |
ensureCapacity(int minimumCapacity)
copy-> .ensureCapacity( )copy-> <StringBuffer>.ensureCapacity(<int minimumCapacity>);
|
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
copy-> .getChars(, , , )copy-> <StringBuffer>.getChars(<int srcBegin>, <int srcEnd>, <char[] dst>, <int dstBegin>);
|
StringBuffer |
insert(int offset,
boolean b)
copy-> .insert(, )copy-> <StringBuffer var>=<StringBuffer>.insert(<int offset>, <boolean b>);
|
StringBuffer |
insert(int offset,
char c)
copy-> .insert(, )copy-> <StringBuffer var>=<StringBuffer>.insert(<int offset>, <char c>);
|
StringBuffer |
insert(int offset,
char[] str)
copy-> .insert(, )copy-> <StringBuffer var>=<StringBuffer>.insert(<int offset>, <char[] str>);
|
StringBuffer |
insert(int index,
char[] str,
int offset,
int len)
copy-> .insert(, , , )copy-> <StringBuffer var>=<StringBuffer>.insert(<int index>, <char[] str>, <int offset>, <int len>);
|
StringBuffer |
insert(int offset,
double d)
copy-> .insert(, )copy-> <StringBuffer var>=<StringBuffer>.insert(<int offset>, <double d>);
|
StringBuffer |
insert(int offset,
float f)
copy-> .insert(, )copy-> <StringBuffer var>=<StringBuffer>.insert(<int offset>, <float f>);
|
StringBuffer |
insert(int offset,
int i)
copy-> .insert(, )copy-> <StringBuffer var>=<StringBuffer>.insert(<int offset>, <int i>);
|
StringBuffer |
insert(int offset,
long l)
copy-> .insert(, )copy-> <StringBuffer var>=<StringBuffer>.insert(<int offset>, <long l>);
|
StringBuffer |
insert(int offset,
Object obj)
copy-> .insert(, )copy-> <StringBuffer var>=<StringBuffer>.insert(<int offset>, <Object obj>);
|
StringBuffer |
insert(int offset,
String str)
copy-> .insert(, )copy-> <StringBuffer var>=<StringBuffer>.insert(<int offset>, <String str>);
|
int |
length()
copy-> .length()copy-> <int var>=<StringBuffer>.length();
|
StringBuffer |
replace(int start,
int end,
String str)
copy-> .replace(, , )copy-> <StringBuffer var>=<StringBuffer>.replace(<int start>, <int end>, <String str>);
|
StringBuffer |
reverse()
copy-> .reverse()copy-> <StringBuffer var>=<StringBuffer>.reverse();
|
void |
setCharAt(int index,
char ch)
copy-> .setCharAt(, )copy-> <StringBuffer>.setCharAt(<int index>, <char ch>);
|
void |
setLength(int newLength)
copy-> .setLength( )copy-> <StringBuffer>.setLength(<int newLength>);
|
String |
substring(int start)
copy-> .substring( )copy-> <String var>=<StringBuffer>.substring(<int start>);
|
String |
substring(int start,
|