java.lang.Object | ||
java.lang.StringBuilder | Serializable Appendable CharSequence |
A modifiable sequence of characters for use in creating
and modifying Strings. This class is intended as a direct replacement of
StringBuffer for non-concurrent use; unlike
StringBuffer
this class is not synchronized for thread safety.
The majority of the modification methods on this class return
StringBuilder
, so that, like StringBuffer
s,
they can be used in chaining method calls together. For example,
new StringBuilder("One should ").append("always strive ").append("to achieve Harmony")
.
StringBuilder() | ||||||
Constructs an instance with an initial capacity of |
||||||
StringBuilder(int capacity) | ||||||
Constructs an instance with a specified capacity. |
||||||
StringBuilder(CharSequence seq) | ||||||
Constructs an instance that's populated by a CharSequence. |
||||||
StringBuilder(String str) | ||||||
Constructs an instance that's populated by a String. |
StringBuilder | append(double d) | |||||
Appends the String representation of the |
||||||
StringBuilder | append(CharSequence csq) | |||||
Appends the String representation of the |
||||||
StringBuilder | append(long lng) | |||||
Appends the String representation of the |
||||||
StringBuilder | append(int i) | |||||
Appends the String representation of the |
||||||
StringBuilder | append(boolean b) | |||||
Appends the String representation of the |
||||||
StringBuilder | append(Object obj) | |||||
Appends the String representation of the |
||||||
StringBuilder | append(char c) | |||||
Appends the String representation of the |
||||||
StringBuilder | append(char[] ch) | |||||
Appends the String representation of the |
||||||
StringBuilder | append(String str) | |||||
Appends the contents of the String. |
||||||
StringBuilder | append(float f) | |||||
Appends the String representation of the |
||||||
StringBuilder | append(char[] str, int offset, int len) | |||||
Appends the String representation of the subset of the
|
||||||
StringBuilder | append(CharSequence csq, int start, int end) | |||||
Appends the String representation of the subsequence of the
|
||||||
StringBuilder | append(StringBuffer sb) | |||||
Appends the contents of the StringBuffer. |
||||||
StringBuilder | appendCodePoint(int codePoint) | |||||
Appends the encoded Unicode code point to this object. |
||||||
int | capacity() | |||||
Returns the number of characters this StringBuffer can hold without growing. | ||||||
char | charAt(int index) | |||||
Retrieves the character at the |
||||||
int | codePointAt(int index) | |||||
Retrieves the Unicode code point value at the |
||||||
int | codePointBefore(int index) | |||||
Retrieves the Unicode code point value that precedes the
|
||||||
int | codePointCount(int beginIndex, int endIndex) | |||||
Calculates the number of Unicode code points between
|
||||||
StringBuilder | delete(int start, int end) | |||||
Deletes a sequence of characters within this object, shifts any remaining characters to the left and adjusts the length() of this object. |
||||||
StringBuilder | deleteCharAt(int index) | |||||
Deletes a single character within this object, shifts any remaining characters to the left and adjusts the length() of this object. |
||||||
void | ensureCapacity(int min) | |||||
Ensures that this object has a minimum capacity available before requiring the internal buffer to be enlarged. |
||||||
void | getChars(int start, int end, char[] dest, int destStart) | |||||
Copies the requested sequence of characters to be copied to the
|
||||||
int | indexOf(String subString, int start) | |||||
Searches in this StringBuffer for the index of the specified character. | ||||||
int | indexOf(String string) | |||||
Searches in this StringBuffer for the first index of the specified character. | ||||||
StringBuilder | insert(int offset, Object obj) | |||||
Inserts the String representation of the |
||||||
StringBuilder | insert(int offset, String str) | |||||
Inserts the String value passed into this object at the
|
||||||
StringBuilder | insert(int offset, char[] ch) | |||||
Inserts the String representation of the |
||||||
StringBuilder | insert(int offset, boolean b) | |||||
Inserts the String representation of the |
||||||
StringBuilder | insert(int offset, double d) | |||||
Inserts the String representation of the |
||||||
StringBuilder | insert(int offset, char c) | |||||
Inserts the String representation of the |
||||||
StringBuilder | insert(int offset, float f) | |||||
Inserts the String representation of the |
||||||
StringBuilder | insert(int offset, int i) | |||||
Inserts the String representation of the |
||||||
StringBuilder | insert(int offset, CharSequence s) | |||||
Inserts the String representation of the |
||||||
StringBuilder | insert(int offset, CharSequence s, int start, int end) | |||||
Inserts the String representation of the subsequence of the
|
||||||
StringBuilder | insert(int offset, char[] str, int strOffset, int strLen) | |||||
Inserts the String representation of the subsequence of the
|
||||||
StringBuilder | insert(int offset, long l) | |||||
Inserts the String representation of the |
||||||
int | lastIndexOf(String string) | |||||
Searches in this StringBuffer for the last index of the specified character. | ||||||
int | lastIndexOf(String subString, int start) | |||||
Searches in this StringBuffer for the index of the specified character. | ||||||
int | length() | |||||
The current length of this object. |
||||||
int | offsetByCodePoints(int index, int codePointOffset) | |||||
Returns the index within this object that is offset from
|
||||||
StringBuilder | replace(int start, int end, String str) | |||||
Replaces the indicated subsequence of this object with the String passed. |
||||||
StringBuilder | reverse() | |||||
Reverses the contents of this object. |
||||||
void | setCharAt(int index, char ch) | |||||
Sets the character at the |
||||||
void | setLength(int length) | |||||
Sets the current length to a new value. |
||||||
CharSequence | subSequence(int start, int end) | |||||
Returns a |
||||||
String | substring(int start, int end) | |||||
Returns the String value of the subsequence of this object from the
|
||||||
String | substring(int start) | |||||
Returns the String value of the subsequence of this object from the
|
||||||
String | toString() | |||||
Returns the contents of this StringBuilder. | ||||||
void | trimToSize() | |||||
Trims off any extra capacity beyond the current length. |
Constructs an instance with an initial capacity of 16
.
Constructs an instance with a specified capacity.
capacity | The initial capacity to use. |
---|
NegativeArraySizeException | if the capacity
parameter is null . |
---|
Constructs an instance that's populated by a CharSequence. The
capacity of the new builder will be the length of the
CharSequence
plus 16.
seq | The CharSequence to copy into the builder. |
---|
NullPointerException | if the seq parameter is
null .
|
---|
Constructs an instance that's populated by a String. The
capacity of the new builder will be the length of the
String
plus 16.
str | The String to copy into the builder. |
---|
NullPointerException | if the str parameter is
null .
|
---|
Appends the String representation of the double
value
passed. The double
value is converted to a String
according to the rule defined by valueOf(double).
d | The double value to append to this object. |
---|
Appends the String representation of the CharSequence
value passed. If the CharSequence
is null
,
then the String "null"
is appended.
csq | The CharSequence value to append to this
object. |
---|
Appends the String representation of the long
value
passed. The long
value is converted to a String according
to the rule defined by valueOf(long).
lng | The long value to append to this object. |
---|
Appends the String representation of the int
value passed.
The int
value is converted to a String according to the
rule defined by valueOf(int).
i | The int value to append to this object. |
---|
Appends the String representation of the boolean
value
passed. The boolean
value is converted to a String
according to the rule defined by valueOf(boolean).
b | The boolean value to append to this object. |
---|
Appends the String representation of the Object
value
passed. The Object
value is converted to a String
according to the rule defined by valueOf(Object).
obj | The Object value to append to this object. |
---|
Appends the String representation of the char
value
passed. The char
value is converted to a String according
to the rule defined by valueOf(char).
c | The char value to append to this object. |
---|
Appends the String representation of the char[]
value
passed. The char[]
value is converted to a String
according to the rule defined by valueOf(char[]).
ch | The char[] value to append to this object. |
---|
Appends the contents of the String. If the String passed is
null
, then the String "null"
is appended.
str | The String to append to this object. |
---|
Appends the String representation of the float
value
passed. The float
value is converted to a String according
to the rule defined by valueOf(float).
f | The float value to append to this object. |
---|
Appends the String representation of the subset of the
char[]
value passed. The char[]
value is
converted to a String according to the rule defined by
valueOf(char[], int, int).
str | The char[] value to append to this object. |
---|---|
offset | The inclusive offset index to begin copying from the
str parameter. |
len | The number of character to copy from the str
parameter. |
Appends the String representation of the subsequence of the
CharSequence
value passed. If the
CharSequence
is null
, then the String
"null"
is used to extract the subsequence from.
csq | The CharSequence value to append to this
object. |
---|---|
start | The beginning index of the subsequence. |
end | The ending index of the subsequence. |
Appends the contents of the StringBuffer. If the StringBuffer passed is
null
, then the StringBuffer "null"
is
appended.
sb | The StringBuffer to append to this object. |
---|
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. |
---|
Retrieves the character at the index
.
index | index of character in this object to retrieve. |
---|
IndexOutOfBoundsException | if index is negative or greater than or equal
to the current 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 sequence of characters within this object, shifts any remaining characters to the left and adjusts the length() of this object.
start | The inclusive start index to begin deletion. |
---|---|
end | The exclusive end index to stop deletion. |
StringIndexOutOfBoundsException | if start is less
than zero, greater than the current length or greater than
end .
|
---|
Deletes a single character within this object, shifts any remaining characters to the left and adjusts the length() of this object.
index | The index of the character to delete. |
---|
StringIndexOutOfBoundsException | if index is less
than zero or is greater than or equal to the current length.
|
---|
Ensures that this object has a minimum capacity available before
requiring the internal buffer to be enlarged. The general policy of this
method is that if the minimumCapacity
is larger than the
current capacity(), then the capacity will be increased to the
largest value of either the minimumCapacity
or the current
capacity multiplied by two plus two. Although this is the general policy,
there is no guarantee that the capacity will change.
min | The new minimum capacity to set. |
---|
Copies the requested sequence of characters to be copied to the
char[]
passed.
start | The inclusive start index of the characters to copy from this object. |
---|---|
end | The exclusive end index of the characters to copy from this object. |
dest | The char[] to copy the characters to. |
destStart | The inclusive start index of the dest parameter
to begin copying to. |
IndexOutOfBoundsException | if the start is negative, the
destStart is negative, the start
is greater than end , the end
is greater than the current length() or
destStart + end - begin is greater than
dest.length .
|
---|
subString | the string to find |
---|---|
start | the starting offset |
string | the string to find |
---|
Inserts the String representation of the Object
value
passed into this object at the offset
passed. The
Object
value is converted to a String according to the
rule defined by valueOf(Object).
offset | The index of this object to insert the value. |
---|---|
obj | The Object value to insert into this object. |
StringIndexOutOfBoundsException | if offset is
negative or greater than the current length(). |
---|
Inserts the String value passed into this object at the
offset
passed. If the String parameter is null, then the
String "null"
is inserted.
offset | The index of this object to insert the value. |
---|---|
str | The String to insert into this object. |
StringIndexOutOfBoundsException | if offset is
negative or greater than the current length().
|
---|
Inserts the String representation of the char[]
value
passed into this object at the offset
passed. The
char[]
value is converted to a String according to the
rule defined by valueOf(char[]).
offset | The index of this object to insert the value. |
---|---|
ch | The char[] value to insert into this object. |
StringIndexOutOfBoundsException | if offset is
negative or greater than the current length(). |
---|
Inserts the String representation of the boolean
value
passed into this object at the offset
passed. The
boolean
value is converted to a String according to the
rule defined by valueOf(boolean).
offset | The index of this object to insert the value. |
---|---|
b | The boolean value to insert into this object. |
StringIndexOutOfBoundsException | if offset is
negative or greater than the current length(). |
---|
Inserts the String representation of the double
value
passed into this object at the offset
passed. The
double
value is converted to a String according to the
rule defined by valueOf(double).
offset | The index of this object to insert the value. |
---|---|
d | The double value to insert into this object. |
StringIndexOutOfBoundsException | if offset is
negative or greater than the current length(). |
---|
Inserts the String representation of the char
value passed
into this object at the offset
passed. The
char
value is converted to a String according to the rule
defined by valueOf(char).
offset | The index of this object to insert the value. |
---|---|
c | The char value to insert into this object. |
ArrayIndexOutOfBoundsException | if offset is
negative or greater than the current length(). |
---|
Inserts the String representation of the float
value
passed into this object at the offset
passed. The
float
value is converted to a String according to the rule
defined by valueOf(float).
offset | The index of this object to insert the value. |
---|---|
f | The float value to insert into this object. |
StringIndexOutOfBoundsException | if offset is
negative or greater than the current length(). |
---|
Inserts the String representation of the int
value passed
into this object at the offset
passed. The
int
value is converted to a String according to the rule
defined by valueOf(int).
offset | The index of this object to insert the value. |
---|---|
i | The int value to insert into this object. |
StringIndexOutOfBoundsException | if offset is
negative or greater than the current length(). |
---|
Inserts the String representation of the CharSequence
value passed into this object at the offset
passed. The
CharSequence
value is converted to a String as defined by
toString(). If the CharSequence
is
null
, then the String "null"
is inserted.
offset | The index of this object to insert the value. |
---|---|
s | The CharSequence value to insert into this
object. |
IndexOutOfBoundsException | if offset is negative or
greater than the current length(). |
---|
Inserts the String representation of the subsequence of the
CharSequence
value passed into this object at the
offset
passed. The CharSequence
value is
converted to a String as defined by
subSequence(int, int). If the
CharSequence
is null
, then the String
"null"
is used to determine the subsequence.
offset | The index of this object to insert the value. |
---|---|
s | The CharSequence value to insert into this
object. |
start | The start of the subsequence of the s
parameter. |
end | The end of the subsequence of the s parameter. |
IndexOutOfBoundsException | if offset is negative or
greater than the current length(). |
---|
Inserts the String representation of the subsequence of the
char[]
value passed into this object at the
offset
passed. The char[]
value is
converted to a String according to the rule defined by
valueOf(char[], int, int).
offset | The index of this object to insert the value. |
---|---|
str | The char[] value to insert into this object. |
strOffset | The inclusive index of the str parameter
to start copying from. |
strLen | The number of characters to copy from the str
parameter. |
StringIndexOutOfBoundsException | if offset is
negative or greater than the current length(). |
---|
Inserts the String representation of the long
value passed
into this object at the offset
passed. The
long
value is converted to a String according to the rule
defined by valueOf(long).
offset | The index of this object to insert the value. |
---|---|
l | The long value to insert into this object. |
StringIndexOutOfBoundsException | if offset is
negative or greater than the current length(). |
---|
string | the string to find |
---|
NullPointerException | if the string parameter is null . |
---|
subString | the string to find |
---|---|
start | the starting offset |
NullPointerException | if the subString parameter is
null . |
---|
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 . |
---|
Replaces the indicated subsequence of this object with the String passed. If the String passed is longer or shorter than the subsequence, then this object will be adjusted appropriately.
start | The inclusive start index of the sequence to replace in this object. |
---|---|
end | The exclusive end index of the sequence to replace in this object. |
str | The String to replace the subsequence. |
StringIndexOutOfBoundsException | if start is
negative, greater than the current length() or greater
than end . |
---|---|
NullPointerException | if the str parameter is
null .
|
Reverses the contents of this object.
Sets the character at the index
in this object.
index | the zero-based index of the character to replace. |
---|---|
ch | the character to set. |
IndexOutOfBoundsException | if index is negative or greater than or equal
to the current length().
|
---|
Sets the current length to a new value. If the new length is larger than
the current length, then the new characters at the end of this object
will contain the char
value of