java.lang.Objectjava.lang.AbstractStringBuilder
java.lang.StringBuffer
All Implemented Interfaces:
CharSequence, java$io$Serializable, Appendable
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.
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)
.
Whenever an operation occurs involving a source sequence (such as appending or inserting from a source sequence) this class synchronizes only on the string buffer performing the operation, not on the source.
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. As of release JDK 5, this class has been supplemented with an equivalent class designed for use by a single thread, StringBuilder . The StringBuilder class should generally be used in preference to this one, as it supports all of the same operations but it is faster, as it performs no synchronization.
Arthur
- van HoffJDK1.0
- Field Summary | ||
---|---|---|
static final long | serialVersionUID | use serialVersionUID from JDK 1.0.2 for interoperability |
Fields inherited from java.lang.AbstractStringBuilder: |
---|
value, count |
Constructor: |
---|
|
|
16 plus the length of the string argument.
|
CharSequence . The initial capacity of
the string buffer is 16 plus the length of the
CharSequence argument.
If the length of the specified
|
Method from java.lang.StringBuffer Summary: |
---|
append, append, append, append, append, append, append, append, append, append, append, append, append, appendCodePoint, capacity, charAt, codePointAt, codePointBefore, codePointCount, delete, deleteCharAt, ensureCapacity, getChars, indexOf, indexOf, insert, insert, insert, insert, insert, insert, insert, insert, insert, insert, insert, insert, lastIndexOf, lastIndexOf, length, offsetByCodePoints, replace, reverse, setCharAt, setLength, subSequence, substring, substring, toString, trimToSize |
Methods from java.lang.AbstractStringBuilder: |
---|
append, append, append, append, append, append, append, append, append, append, append, append, append, appendCodePoint, capacity, charAt, codePointAt, codePointBefore, codePointCount, delete, deleteCharAt, ensureCapacity, expandCapacity, getChars, getValue, indexOf, indexOf, insert, insert, insert, insert, insert, insert, insert, insert, insert, insert, insert, insert, lastIndexOf, lastIndexOf, length, offsetByCodePoints, replace, reverse, setCharAt, setLength, subSequence, substring, substring, toString, trimToSize |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from java.lang.StringBuffer Detail: |
---|
|
|
The characters of the StringBuffer argument are appended, in order, to the contents of this StringBuffer, increasing the length of this StringBuffer by the length of the argument. If sb is null, then the four characters "null" are appended to this StringBuffer.
Let n be the length of the old character sequence, the one
contained in the StringBuffer just prior to execution of the
append method. Then the character at index k in
the new character sequence is equal to the character at index k
in the old character sequence, if k is less than n;
otherwise, it is equal to the character at index k-n in the
argument
This method synchronizes on |
CharSequence to this
sequence.
The characters of the The result of this method is exactly the same as if it were an invocation of this.append(s, 0, s.length()); This method synchronizes on this (the destination)
object but does not synchronize on the source ( If |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|