| java.lang.Object | |
| ↳ | java.lang.StringBuffer |
StringBuffer is a variable size contiguous indexable array of characters. The length of the StringBuffer is the number of characters it contains. The capacity of the StringBuffer is the number of characters it can hold.
Characters may be inserted at any position up to the length of the StringBuffer, increasing the length of the StringBuffer. Characters at any position in the StringBuffer may be replaced, which does not affect the StringBuffer length.
The capacity of a StringBuffer may be specified when the StringBuffer is created. If the capacity of the StringBuffer is exceeded, the capacity is increased.
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new StringBuffer using the default capacity.
| |||||||||||
Constructs a new StringBuffer using the specified capacity.
| |||||||||||
Constructs a new StringBuffer containing the characters in the specified
string and the default capacity.
| |||||||||||
Constructs a StringBuffer and initializes it with the characters in the
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adds the string representation of the specified double to the end of this
StringBuffer.
| |||||||||||
Appends the | |||||||||||
Adds the string representation of the specified long to the end of this
StringBuffer.
| |||||||||||
Adds the string representation of the specified integer to the end of
this StringBuffer.
| |||||||||||
Adds the string representation of the specified boolean to the end of
this StringBuffer.
| |||||||||||
Adds the string representation of the specified object to the end of this
StringBuffer.
| |||||||||||
Adds the specified character to the end of this StringBuffer.
| |||||||||||
Adds the character array to the end of this StringBuffer.
| |||||||||||
Adds the specified string to the end of this StringBuffer.
| |||||||||||
Adds the string representation of the specified float to the end of this
StringBuffer.
| |||||||||||
Adds the specified sequence of characters to the end of this
StringBuffer.
| |||||||||||
Appends the subsequence of the | |||||||||||
Adds the specified StringBuffer to the end of this StringBuffer.
| |||||||||||
Appends the encoded Unicode code point to this object. | |||||||||||
Returns the number of characters this StringBuffer can hold without
growing.
| |||||||||||
Returns the character at the specified offset in this StringBuffer.
| |||||||||||
Retrieves the Unicode code point value at the | |||||||||||
Retrieves the Unicode code point value that precedes the
| |||||||||||
Calculates the number of Unicode code points between
| |||||||||||
Deletes a range of characters.
| |||||||||||
Deletes a single character
| |||||||||||
Ensures that this StringBuffer can hold the specified number of
characters without growing.
| |||||||||||
Copies the specified characters in this StringBuffer to the character
array starting at the specified offset in the character array.
| |||||||||||
Searches in this StringBuffer for the index of the specified character.
| |||||||||||
Searches in this StringBuffer for the first index of the specified
character.
| |||||||||||
Inserts the string representation of the specified object at the
specified offset in this StringBuffer.
| |||||||||||
Inserts the string at the specified offset in this StringBuffer.
| |||||||||||
Inserts the character array at the specified offset in this StringBuffer.
| |||||||||||
Inserts the string representation of the specified boolean at the
specified offset in this StringBuffer.
| |||||||||||
Inserts the string representation of the specified double at the
specified offset in this StringBuffer.
| |||||||||||
Inserts the character at the specified offset in this StringBuffer.
| |||||||||||
Inserts the string representation of the specified float at the specified
offset in this StringBuffer.
| |||||||||||
Inserts the string representation of the specified integer at the
specified offset in this StringBuffer.
| |||||||||||
Inserts the | |||||||||||
Inserts the | |||||||||||
Inserts the specified sequence of characters at the specified offset in
this StringBuffer.
| |||||||||||
Inserts the string representation of the specified long at the specified
offset in this StringBuffer.
| |||||||||||
Searches in this StringBuffer for the last index of the specified
character.
| |||||||||||
Searches in this StringBuffer for the index of the specified character.
| |||||||||||
The current length of this object. | |||||||||||
Returns the index within this object that is offset from
| |||||||||||
Replace a range of characters with the characters in the specified
String.
| |||||||||||
Reverses the order of characters in this StringBuffer.
| |||||||||||
Sets the character at the specified offset in this StringBuffer.
| |||||||||||
Sets the length of this StringBuffer to the specified length.
| |||||||||||
Copies a range of characters into a new String.
| |||||||||||
Copies a range of characters into a new String.
| |||||||||||
Copies a range of characters into a new String.
| |||||||||||
Returns the contents of this StringBuffer.
| |||||||||||
Trims the storage capacity of this buffer down to the size of the current character sequence. | |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
From interface java.lang.Appendable
| |||||||||||
From interface java.lang.CharSequence
| |||||||||||
Constructs a new StringBuffer using the default capacity.
Constructs a new StringBuffer using the specified capacity.
| capacity | the initial capacity |
|---|
Constructs a new StringBuffer containing the characters in the specified string and the default capacity.
| string | the string content with which to initialize the new
StringBuffer instance |
|---|
| NullPointerException | on supplying a null value of
string
|
|---|
Constructs a StringBuffer and initializes it with the characters in the
CharSequence.
| cs | The CharSequence to initialize the instance. |
|---|
| NullPointerException | if the cs parameter is null. |
|---|
Adds the string representation of the specified double to the end of this StringBuffer.
| d | the double |
|---|
Appends the CharSequence to this buffer. If the
CharSequence is null, then the string
"null" is appended.
| s | The CharSequence to append. |
|---|
Adds the string representation of the specified long to the end of this StringBuffer.
| l | the long |
|---|
Adds the string representation of the specified integer to the end of this StringBuffer.
| i | the integer |
|---|
Adds the string representation of the specified boolean to the end of this StringBuffer.
| b | the boolean |
|---|
Adds the string representation of the specified object to the end of this StringBuffer.
| obj | the object |
|---|
Adds the specified character to the end of this StringBuffer.
| ch | a character |
|---|
Adds the character array to the end of this StringBuffer.
| chars | the character array |
|---|
| NullPointerException | when chars is null |
|---|
Adds the specified string to the end of this StringBuffer.
| string | the string |
|---|
Adds the string representation of the specified float to the end of this StringBuffer.
| f | the float |
|---|
Adds the specified sequence of characters to the end of this StringBuffer.
| chars | a character array |
|---|---|
| start | the starting offset |
| length | the number of characters |
| ArrayIndexOutOfBoundsException | when length < 0, start < 0 or
start + length > chars.length |
|---|---|
| NullPointerException | when chars is null |
Appends the subsequence of the CharSequence to this
buffer. If the CharSequence is null, then
the string "null" is used to extract a subsequence.
| s | The CharSequence to append. |
|---|---|
| start | The inclusive start index of the subsequence of the
CharSequence. |
| end | The exclusive end index of the subsequence of the
CharSequence. |
| IndexOutOfBoundsException | if start or end are negative,
start is greater than end or
end is greater than the length of
s.
|
|---|
Adds the specified StringBuffer to the end of this StringBuffer.
| sb | the StringBuffer |
|---|
Appends the encoded Unicode code point to this object. The code point is
converted to a char[] as defined by
toChars(int).
| codePoint | The Unicode code point to encode and append. |
|---|
Returns the number of characters this StringBuffer can hold without growing.
Returns the character at the specified offset in this StringBuffer.
| index | the zero-based index in this StringBuffer |
|---|
| IndexOutOfBoundsException | when index < 0 or
index >= length()
|
|---|
Retrieves the Unicode code point value at the index.
| index | The index to the char code unit within this
object. |
|---|
| IndexOutOfBoundsException | if index is negative or greater than or equal
to length(). |
|---|
Retrieves the Unicode code point value that precedes the
index.
| index | The index to the char code unit within this
object. |
|---|
| IndexOutOfBoundsException | if index is less than 1 or greater than
length(). |
|---|
Calculates the number of Unicode code points between
beginIndex and endIndex.
| beginIndex | The inclusive beginning index of the subsequence. |
|---|---|
| endIndex | The exclusive end index of the subsequence. |
| IndexOutOfBoundsException | if beginIndex is negative or greater than
endIndex or endIndex is greater
than length(). |
|---|
Deletes a range of characters.
| start | the offset of the first character |
|---|---|
| end | the offset one past the last character |
| StringIndexOutOfBoundsException | when start < 0, start > end or
end > length()
|
|---|
Deletes a single character
| location | the offset of the character to delete |
|---|
| StringIndexOutOfBoundsException | when location < 0 or
location >= length()
|
|---|
Ensures that this StringBuffer can hold the specified number of characters without growing.
| min | the minimum number of elements that this StringBuffer will hold before growing |
|---|
Copies the specified characters in this StringBuffer to the character array starting at the specified offset in the character array.
| start | the starting offset of characters to copy |
|---|---|
| end | the ending offset of characters to copy |
| buffer | the destination character array |
| idx | the starting offset in the character array |
| IndexOutOfBoundsException | when start < 0, end > length(),
start > end, index < 0, end - start > buffer.length - index |
|---|---|
| NullPointerException | when buffer is null |
Searches in this StringBuffer for the index of the specified character. The search for the character starts at the specified offset and moves towards the end.
| subString | the string to find |
|---|---|
| start | the starting offset |
Searches in this StringBuffer for the first index of the specified character. The search for the character starts at the beginning and moves towards the end.
| string | the string to find |
|---|
Inserts the string representation of the specified object at the specified offset in this StringBuffer.
| index | the index at which to insert |
|---|---|
| obj | the object to insert |
| StringIndexOutOfBoundsException | when index < 0 or
index > length()
|
|---|
Inserts the string at the specified offset in this StringBuffer.
| index | the index at which to insert |
|---|---|
| string | the string to insert |
| StringIndexOutOfBoundsException | when index < 0 or
index > length()
|
|---|
Inserts the character array at the specified offset in this StringBuffer.
| index | the index at which to insert |
|---|---|
| chars | the character array to insert |
| StringIndexOutOfBoundsException | when index < 0 or
index > length() |
|---|---|
| NullPointerException | when chars is null |
Inserts the string representation of the specified boolean at the specified offset in this StringBuffer.
| index | the index at which to insert |
|---|---|
| b | the boolean to insert |
| StringIndexOutOfBoundsException | when index < 0 or
index > length()
|
|---|
Inserts the string representation of the specified double at the specified offset in this StringBuffer.
| index | the index at which to insert |
|---|---|
| d | the double to insert |
| StringIndexOutOfBoundsException | when index < 0 or
index > length()
|
|---|
Inserts the character at the specified offset in this StringBuffer.
| index | the index at which to insert |
|---|---|
| ch | the character to insert |
| ArrayIndexOutOfBoundsException | when index < 0 or
index > length()
|
|---|
Inserts the string representation of the specified float at the specified offset in this StringBuffer.
| index | the index at which to insert |
|---|---|
| f | the float to insert |
| StringIndexOutOfBoundsException | when index < 0 or
index > length()
|
|---|
Inserts the string representation of the specified integer at the specified offset in this StringBuffer.
| index | the index at which to insert |
|---|---|
| i | the integer to insert |
| StringIndexOutOfBoundsException | when index < 0 or
index > length()
|
|---|
Inserts the CharSequence into this buffer at the
index. If CharSequence is
null, then the string "null" is inserted.
| index | The index of this buffer to insert the sequence. |
|---|---|
| s | The CharSequence to insert. |
| IndexOutOfBoundsException | if the index is invalid. |
|---|
Inserts the CharSequence into this buffer at the
index. If CharSequence is
null, then the string "null" is inserted.
| index | The index of this buffer to insert the sequence. |
|---|---|
| s | The CharSequence to insert. |
| start | The inclusive start index of the subsequence of the
CharSequence. |
| end | The exclusive end index of the subsequence of the
CharSequence. |
| IndexOutOfBoundsException | if index is negative or greater than the
current length, start or end
are negative, start is greater than
end or end is greater than the
length of s.
|
|---|
Inserts the specified sequence of characters at the specified offset in this StringBuffer.
| index | the index at which to insert |
|---|---|
| chars | a character array |
| start | the starting offset |
| length | the number of characters |
| StringIndexOutOfBoundsException | when length < 0, start < 0,
start + length > chars.length, index < 0
or index > length() |
|---|---|
| NullPointerException | when chars is null |
Inserts the string representation of the specified long at the specified offset in this StringBuffer.
| index | the index at which to insert |
|---|---|
| l | the long to insert |
| StringIndexOutOfBoundsException | when index < 0 or
index > length()
|
|---|
Searches in this StringBuffer for the last index of the specified character. The search for the character starts at the end and moves towards the beginning.
| string | the string to find |
|---|
| NullPointerException | if the string parameter is null. |
|---|
Searches in this StringBuffer for the index of the specified character. The search for the character starts at the specified offset and moves towards the beginning.
| subString | the string to find |
|---|---|
| start | the starting offset |
The current length of this object.
Returns the index within this object that is offset from
index by codePointOffset code points.
| index | The index within this object to calculate the offset from. |
|---|---|
| codePointOffset | The number of code points to count. |
| IndexOutOfBoundsException | if index is negative or greater than
length() or if there aren't enough code points
before or after index to match
codePointOffset. |
|---|
Replace a range of characters with the characters in the specified String.
| start | the offset of the first character |
|---|---|
| end | the offset one past the last character |
| string | a String |
| StringIndexOutOfBoundsException | when start < 0 or start > end
|
|---|
Reverses the order of characters in this StringBuffer.
Sets the character at the specified offset in this StringBuffer.
| index | the zero-based index in this StringBuffer |
|---|---|
| ch | the character |
| IndexOutOfBoundsException | when index < 0 or
index >= length()
|
|---|
Sets the length of this StringBuffer to the specified length. If there
are more than length characters in this StringBuffer, the characters at
end are lost. If there are less than length characters in the
StringBuffer, the additional characters are set to \\u0000.
| length | the new length of this StringBuffer |
|---|
| IndexOutOfBoundsException | when length < 0 |
|---|
Copies a range of characters into a new String.
| start | the offset of the first character |
|---|---|
| end | the offset one past the last character |
| IndexOutOfBoundsException | when start < 0, start > end or
end > length() |
|---|
Copies a range of characters into a new String.
| start | the offset of the first character |
|---|---|
| end | the offset one past the last character |
| StringIndexOutOfBoundsException | when start < 0, start > end or
end > length()
|
|---|
Copies a range of characters into a new String.
| start | the offset of the first character |
|---|
| StringIndexOutOfBoundsException | when start < 0 or
start > length()
|
|---|
Returns the contents of this StringBuffer.
Trims the storage capacity of this buffer down to the size of the current character sequence. Execution of this method may change the results returned by the capacity() method, but this is not required.