public final class StringBuilder extends Object implements CharSequence
Constructor and Description |
---|
StringBuilder()
Constructs a string builder with no characters in it and an initial capacity of 16 characters.
|
StringBuilder(CharSequence cs) |
StringBuilder(int length)
Constructs a string builder with no characters in it and an initial capacity specified by the length argument.
|
StringBuilder(String str)
Constructs a string builder so that it represents the same sequence of characters as the string argument; in other words, the initial contents of the string builder is a copy of the argument string.
|
Modifier and Type | Method and Description |
---|---|
StringBuilder |
append(boolean b)
Appends the string representation of the boolean argument to the string builder.
|
StringBuilder |
append(char c)
Appends the string representation of the char argument to this string builder.
|
StringBuilder |
append(char[] str) |
StringBuilder |
append(char[] str,
int offset,
int len)
Appends the string representation of a subarray of the char array argument to this string builder.
|
StringBuilder |
append(CharSequence cs) |
StringBuilder |
append(CharSequence cs,
int start,
int end) |
StringBuilder |
append(double d)
Appends the string representation of the double argument to this string builder.
|
StringBuilder |
append(float f)
Appends the string representation of the float argument to this string builder.
|
StringBuilder |
append(int i)
Appends the string representation of the int argument to this string builder.
|
StringBuilder |
append(long l)
Appends the string representation of the long argument to this string builder.
|
StringBuilder |
append(Object obj)
Appends the string representation of the Object argument to this string builder.
|
StringBuilder |
append(String str)
Appends the string to this string builder.
|
StringBuilder |
append(StringBuffer buf)
Appends StringBuffer to end of builder.
|
int |
capacity()
Returns the current capacity of the String builder.
|
char |
charAt(int index)
The specified character of the sequence currently represented by the string builder, as indicated by the index argument, is returned.
|
StringBuilder |
delete(int start,
int end)
Removes the characters in a substring of this StringBuilder.
|
StringBuilder |
deleteCharAt(int index)
Removes the character at the specified position in this StringBuilder (shortening the StringBuilder by one character).
|
void |
ensureCapacity(int minimumCapacity)
Ensures that the capacity of the builder is at least equal to the specified minimum.
|
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Characters are copied from this string builder into the destination character array dst.
|
StringBuilder |
insert(int offset,
boolean b)
Inserts the string representation of the boolean argument into this string builder.
|
StringBuilder |
insert(int offset,
char c)
Inserts the string representation of the char argument into this string builder.
|
StringBuilder |
insert(int offset,
CharSequence cs) |
StringBuilder |
insert(int offset,
CharSequence cs,
int start,
int end) |
StringBuilder |
insert(int offset,
double d)
Inserts the string representation of the double argument into this string builder.
|
StringBuilder |
insert(int offset,
float f)
Inserts the string representation of the float argument into this string builder.
|
StringBuilder |
insert(int offset,
int i)
Inserts the string representation of the second int argument into this string builder.
|
StringBuilder |
insert(int offset,
long l)
Inserts the string representation of the long argument into this string builder.
|
StringBuilder |
insert(int offset,
Object obj)
Inserts the string representation of the Object argument into this string builder.
|
StringBuilder |
insert(int offset,
String str)
Inserts the string into this string builder.
|
int |
length()
Returns the length (character count) of this string builder.
|
StringBuilder |
reverse()
The character sequence contained in this string builder is replaced by the reverse of the sequence.
|
void |
setCharAt(int index,
char ch)
The character at the specified index of this string builder is set to ch.
|
void |
setLength(int newLength)
Sets the length of this string builder.
|
CharSequence |
subSequence(int start,
int end)
Returns a
CharSequence from the start index (inclusive)
to the end index (exclusive) of this sequence. |
String |
toString()
Converts to a string representing the data in this string builder.
|
void |
trimToSize() |
public StringBuilder()
public StringBuilder(int length)
public StringBuilder(String str)
public StringBuilder(CharSequence cs)
public StringBuilder append(boolean b)
public StringBuilder append(char c)
public StringBuilder append(char[] str)
public StringBuilder append(char[] str, int offset, int len)
public StringBuilder append(double d)
public StringBuilder append(float f)
public StringBuilder append(int i)
public StringBuilder append(long l)
public StringBuilder append(Object obj)
public StringBuilder append(String str)
public int capacity()
public char charAt(int index)
charAt
in interface CharSequence
index
- the index of the character to return.public StringBuilder delete(int start, int end)
public StringBuilder append(StringBuffer buf)
buf
- The string buffer to appendpublic StringBuilder deleteCharAt(int index)
public void ensureCapacity(int minimumCapacity)
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
public StringBuilder insert(int offset, boolean b)
public StringBuilder insert(int offset, char c)
public StringBuilder insert(int offset, double d)
public StringBuilder insert(int offset, float f)
public StringBuilder insert(int offset, int i)
public StringBuilder insert(int offset, long l)
public StringBuilder insert(int offset, Object obj)
public StringBuilder insert(int offset, String str)
public int length()
length
in interface CharSequence
public StringBuilder reverse()
public void setCharAt(int index, char ch)
public void setLength(int newLength)
public String toString()
toString
in interface CharSequence
toString
in class Object
public void trimToSize()
public StringBuilder append(CharSequence cs)
public StringBuilder append(CharSequence cs, int start, int end)
public StringBuilder insert(int offset, CharSequence cs)
public StringBuilder insert(int offset, CharSequence cs, int start, int end)
public CharSequence subSequence(int start, int end)
CharSequence
CharSequence
from the start
index (inclusive)
to the end
index (exclusive) of this sequence.subSequence
in interface CharSequence
start
- the start offset of the sub-sequence. It is inclusive, that
is, the index of the first character that is included in the
sub-sequence.end
- the end offset of the sub-sequence. It is exclusive, that is,
the index of the first character after those that are included
in the sub-sequence