|
Final | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.lang.StringBuilder
public final class StringBuilder
StringBuilder is not thread safe. For a synchronized implementation, use StringBuffer. StringBuilder is a variable size contiguous indexable array of characters. The length of the StringBuilder is the number of characters it contains. The capacity of the StringBuilder is the number of characters it can hold.
Characters may be inserted at any position up to the length of the StringBuilder, increasing the length of the StringBuilder. Characters at any position in the StringBuilder may be replaced, which does not affect the StringBuilder length.
The capacity of a StringBuilder may be specified when the StringBuilder is created. If the capacity of the StringBuilder is exceeded, the capacity is increased.
StringBuffer,
Serialized Form| Constructor Summary | |
|---|---|
StringBuilder()
Constructs a new StringBuffer using the default capacity. |
|
StringBuilder(CharSequence sequence)
Constructs a new StringBuilder containing the characters in the specified CharSequence and the default capacity. |
|
StringBuilder(int capacity)
Constructs a new StringBuilder using the specified capacity. |
|
StringBuilder(String string)
Constructs a new StringBuilder containing the characters in the specified string and the default capacity. |
|
| Method Summary | |
|---|---|
StringBuilder |
append(boolean value)
Adds the string representation of the specified boolean to the end of this StringBuilder. |
StringBuilder |
append(char ch)
Adds the specified character to the end of this StringBuilder. |
StringBuilder |
append(char[] chars)
Adds the character array to the end of this StringBuilder. |
StringBuilder |
append(char[] chars,
int start,
int length)
Adds the specified sequence of characters to the end of this StringBuilder. |
StringBuilder |
append(CharSequence sequence)
Adds the specified CharSequence to the end of this StringBuilder. |
StringBuilder |
append(CharSequence sequence,
int start,
int end)
Adds the specified CharSequence to the end of this StringBuilder. |
StringBuilder |
append(double value)
Adds the string representation of the specified double to the end of this StringBuilder. |
StringBuilder |
append(float value)
Adds the string representation of the specified float to the end of this StringBuilder. |
StringBuilder |
append(int value)
Adds the string representation of the specified integer to the end of this StringBuilder. |
StringBuilder |
append(long value)
Adds the string representation of the specified long to the end of this StringBuilder. |
StringBuilder |
append(Object value)
Adds the string representation of the specified object to the end of this StringBuilder. |
StringBuilder |
append(String string)
Adds the specified string to the end of this StringBuilder. |
StringBuilder |
append(StringBuffer buffer)
Adds the specified StringBuffer to the end of this StringBuilder. |
StringBuilder |
appendCodePoint(int codePoint)
Adds the specified code point to the end of this StringBuffer. |
int |
capacity()
Answers the number of characters this StringBuilder can hold without growing. |
char |
charAt(int index)
Answers the character at the specified offset in this StringBuilder. |
int |
codePointAt(int index)
Returns the Unicode character at the given point. |
int |
codePointBefore(int index)
Returns the Unicode character before the given point. |
int |
codePointCount(int start,
int end)
Returns the total Unicode values in the specified range. |
StringBuilder |
delete(int start,
int end)
Deletes a range of characters. |
StringBuilder |
deleteCharAt(int location)
Deletes a single character |
void |
ensureCapacity(int min)
Ensures that this StringBuilder can hold the specified number of characters without growing. |
void |
getChars(int start,
int end,
char[] buffer,
int index)
Copies the specified characters in this StringBuilder to the character array starting at the specified offset in the character array. |
int |
indexOf(String string)
Searches in this StringBuilder for the first index of the specified character. |
int |
indexOf(String subString,
int start)
Searches in this StringBuilder for the index of the specified character. |
StringBuilder |
insert(int index,
boolean value)
Inserts the string representation of the specified boolean at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
char ch)
Inserts the character at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
char[] chars)
Inserts the character array at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
char[] chars,
int start,
int length)
Inserts the specified sequence of characters at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
CharSequence sequence)
Inserts the CharSequence at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
CharSequence sequence,
int start,
int end)
Inserts the CharSequence at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
double value)
Inserts the string representation of the specified double at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
float value)
Inserts the string representation of the specified float at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
int value)
Inserts the string representation of the specified integer at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
long value)
Inserts the string representation of the specified long at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
Object value)
Inserts the string representation of the specified object at the specified offset in this StringBuilder. |
StringBuilder |
insert(int index,
String string)
Inserts the string at the specified offset in this StringBuilder. |
int |
lastIndexOf(String string)
Searches in this StringBuilder for the last index of the specified character. |
int |
lastIndexOf(String subString,
int start)
Searches in this StringBuilder for the index of the specified character. |
int |
length()
Answers the size of this StringBuilder. |
int |
offsetByCodePoints(int start,
int codePointCount)
Returns the index of the code point that was offset by codePointCount. |
StringBuilder |
replace(int start,
int end,
String string)
Replace a range of characters with the characters in the specified String. |
StringBuilder |
reverse()
Reverses the order of characters in this StringBuilder. |
void |
setCharAt(int index,
char ch)
Sets the character at the specified offset in this StringBuilder. |
void |
setLength(int length)
Sets the length of this StringBuilder to the specified length. |
CharSequence |
subSequence(int start,
int end)
Copies a range of characters into a new String. |
String |
substring(int start)
Copies a range of characters into a new String. |
String |
substring(int start,
int end)
Copies a range of characters into a new String. |
String |
toString()
Answers the contents of this StringBuilder. |
void |
trimToSize()
Optionally modify the underlying char array to only be large enough to hold the characters in this StringBuffer. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public StringBuilder()
public StringBuilder(int capacity)
capacity - the initial capacitypublic StringBuilder(String string)
string - the initial contents of this StringBuilder
NullPointerException - when string is nullpublic StringBuilder(CharSequence sequence)
sequence - the initial contents of this StringBuilder
NullPointerException - when squence is null| Method Detail |
|---|
public StringBuilder append(char[] chars)
chars - the character array
NullPointerException - when chars is nullpublic StringBuilder append(char[] chars,
int start,
int length)
chars - a character arraystart - the starting offsetlength - the number of characters
IndexOutOfBoundsException - when length < 0, start < 0 or
start + length > chars.length
NullPointerException - when chars is nullpublic StringBuilder append(char ch)
append in interface Appendablech - a character
public StringBuilder append(double value)
value - the double
public StringBuilder append(float value)
value - the float
public StringBuilder append(int value)
value - the integer
public StringBuilder append(long value)
value - the long
public StringBuilder append(Object value)
value - the object
public StringBuilder append(String string)
string - the string
public StringBuilder append(boolean value)
value - the boolean
public int capacity()
ensureCapacity(int),
length()public char charAt(int index)
charAt in interface CharSequenceindex - the zero-based index in this StringBuilder
IndexOutOfBoundsException - when index < 0 or
index >= length()public StringBuilder delete(int start,
int end)
start - the offset of the first characterend - the offset one past the last character
StringIndexOutOfBoundsException - when start < 0, start > end or
end > length()public StringBuilder deleteCharAt(int location)
location - the offset of the character to delete
StringIndexOutOfBoundsException - when location < 0 or
location >= length()public void ensureCapacity(int min)
min - the minimum number of elements that this
StringBuilder will hold before growingpublic void getChars(int start,
int end,
char[] buffer,
int index)
start - the starting offset of characters to copyend - the ending offset of characters to copybuffer - the destination character arrayindex - 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 nullpublic StringBuilder insert(int index,
char[] chars)
index - the index at which to insertchars - the character array to insert
StringIndexOutOfBoundsException - when index < 0 or
index > length()
NullPointerException - when chars is nullpublic StringBuilder insert(int index,
char[] chars,
int start,
int length)
index - the index at which to insertchars - a character arraystart - the starting offsetlength - the number of characters
StringIndexOutOfBoundsException - when length < 0, start < 0,
start + length > chars.length, index < 0 or
index > length()
NullPointerException - when chars is nullpublic StringBuilder insert(int index,
char ch)
index - the index at which to insertch - the character to insert
IndexOutOfBoundsException - when index < 0 or
index > length()public StringBuilder insert(int index,
double value)
index - the index at which to insertvalue - the double to insert
StringIndexOutOfBoundsException - when index < 0 or
index > length()public StringBuilder insert(int index,
float value)
index - the index at which to insertvalue - the float to insert
StringIndexOutOfBoundsException - when index < 0 or
index > length()public StringBuilder insert(int index,
int value)
index - the index at which to insertvalue - the integer to insert
StringIndexOutOfBoundsException - when index < 0 or
index > length()public StringBuilder insert(int index,
long value)
index - the index at which to insertvalue - the long to insert
StringIndexOutOfBoundsException - when index < 0 or
index > length()public StringBuilder insert(int index,
Object value)
index - the index at which to insertvalue - the object to insert
StringIndexOutOfBoundsException - when index < 0 or
index > length()public StringBuilder insert(int index,
String string)
index - the index at which to insertstring - the string to insert
StringIndexOutOfBoundsException - when index < 0 or
index > length()public StringBuilder insert(int index,
boolean value)
index - the index at which to insertvalue - the boolean to insert
StringIndexOutOfBoundsException - when index < 0 or
index > length()public int length()
length in interface CharSequencepublic StringBuilder replace(int start,
int end,
String string)
start - the offset of the first characterend - the offset one past the last characterstring - a String
StringIndexOutOfBoundsException - when start < 0 or
start > endpublic StringBuilder reverse()
public void setCharAt(int index,
char ch)
index - the zero-based index in this StringBuilderch - the character
IndexOutOfBoundsException - when index < 0 or
index >= length()public void setLength(int length)
\\u0000.
length - the new length of this StringBuilder
IndexOutOfBoundsException - when length < 0length()public String substring(int start)
start - the offset of the first character
StringIndexOutOfBoundsException - when start < 0 or
start > length()public String substring(int start,
int end)
start - the offset of the first characterend - the offset one past the last character
StringIndexOutOfBoundsException - when start < 0, start > end or
end > length()public String toString()
toString in interface CharSequencetoString in class Objectpublic StringBuilder append(StringBuffer buffer)
buffer - the StringBuffer
public CharSequence subSequence(int start,
int end)
subSequence in interface CharSequencestart - the offset of the first characterend - the offset one past the last character
IndexOutOfBoundsException - when start < 0, start > end or
end > length()public int indexOf(String string)
string - the string to find
lastIndexOf(String)public int indexOf(String subString,
int start)
subString - the string to findstart - the starting offset
lastIndexOf(String,int)public int lastIndexOf(String string)
string - the string to find
indexOf(String)public int lastIndexOf(String subString,
int start)
subString - the string to findstart - the starting offset
indexOf(String,int)public StringBuilder append(CharSequence sequence)
append in interface Appendablesequence - the CharSequence
public StringBuilder append(CharSequence sequence,
int start,
int end)
append in interface Appendablesequence - the CharSequencestart - the offset of the first characterend - the offset one past the last character
IndexOutOfBoundsException - when start < 0, start > end or
end > length()public StringBuilder insert(int index,
CharSequence sequence)
index - the index at which to insertsequence - the CharSequence to insert
IndexOutOfBoundsException - when index < 0 or
index > length()public StringBuilder insert(int index,
CharSequence sequence,
int start,
int end)
index - the index at which to insertsequence - the CharSequence to insertstart - the offset of the first characterend - the offset one past the last character
IndexOutOfBoundsException - when index < 0 or
index > length(), or when start < 0, start > end or
end > length()public void trimToSize()
public int codePointAt(int index)
index - the character index
public int codePointBefore(int index)
index - the character index
public int codePointCount(int start,
int end)
start - first indexend - last index
public int offsetByCodePoints(int start,
int codePointCount)
codePointCount.
start - the position to offsetcodePointCount - the code point count
public StringBuilder appendCodePoint(int codePoint)
codePoint - the code point
|
Final | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||