public final class StringBuilder extends Object
| Constructor and Description |
|---|
StringBuilder()
Constructs a string builder with initial capacity of 32.
|
StringBuilder(int cap)
Constructs a string builder with initial capacity specified.
|
StringBuilder(String str)
Constructs a string builder initialized to the contents of the
specified string.
|
| Modifier and Type | Method and Description |
|---|---|
StringBuilder |
append(boolean b)
Appends "true" or "false" boolean value to content.
|
StringBuilder |
append(char c)
Appends character to content.
|
StringBuilder |
append(char[] str)
Appends character array data to content.
|
StringBuilder |
append(char[] str,
int ofs,
int len)
Append character data from array starting at offset for the defined length.
|
StringBuilder |
append(double d)
Appends the value of (@code double) to content.
|
StringBuilder |
append(float f)
Appends the value of (@code float) to content.
|
StringBuilder |
append(int i)
Appends the value of (@code int) to content.
|
StringBuilder |
append(long lng)
Appends the value of (@code long) to content.
|
StringBuilder |
append(Object obj)
Append string representation of the object to content.
|
StringBuilder |
append(String str)
Appends the provided string.
|
StringBuilder |
append(StringBuffer sb)
Appends content from the supplied (@code StringBuffer) to content.
|
int |
capacity()
Returns the current size of the array (capacity)
|
char |
charAt(int index)
Returns the (@code char) value at the specified index.
|
StringBuilder |
delete(int start,
int end)
Removes the specified range from the content array.
|
StringBuilder |
deleteCharAt(int idx)
Removes the character from the content sequence.
|
void |
ensureCapacity(int size)
Make sure that the character array is large enough to store
the specified number of characters.
|
void |
getChars(int from,
int to,
char[] arr,
int start)
Moves characters from the starting index to the ending index-1 from the
content character array into the supplied array at the specified starting
index.
|
int |
indexOf(String str)
Returns the index within this string of the first occurrence of the specified substring.
|
int |
indexOf(String str,
int from)
Returns the index within this string of the first occurrence of the specified substring.
|
StringBuilder |
insert(int ofs,
boolean bool)
Inserts "true" or "false" into the string at the specified offset based upon a boolean value.
|
StringBuilder |
insert(int ofs,
char ch)
Inserts the a character into the string at the specified offset.
|
StringBuilder |
insert(int ofs,
char[] arr)
Inserts the character array into the string at the specified offset.
|
StringBuilder |
insert(int idx,
char[] arr,
int ofs,
int len)
Inserts a subset of a character array into the string at the specified offset.
|
StringBuilder |
insert(int ofs,
double val)
Inserts the string representation of a double value into the string at the specified offset.
|
StringBuilder |
insert(int ofs,
float val)
Inserts the string representation of a float value into the string at the specified offset.
|
StringBuilder |
insert(int ofs,
int val)
Inserts the string representation of a int value into the string at the specified offset.
|
StringBuilder |
insert(int ofs,
long val)
Inserts the string representation of a long value into the string at the specified offset.
|
StringBuilder |
insert(int ofs,
Object obj)
Inserts a string representation of the object into the string at the specified offset.
|
StringBuilder |
insert(int ofs,
String str)
Inserts into the string at the specified offset.
|
int |
lastIndexOf(String str)
Returns the index within this string of the last occurrence of the specified substring.
|
int |
lastIndexOf(String str,
int from)
Returns the index within this string of the last occurrence of the specified substring.
|
int |
length()
Returns the length of the current content
|
StringBuilder |
replace(int start,
int end,
String str)
Replaces a section in the content sequence.
|
void |
setCharAt(int index,
char ch)
The character at the specified index is set to the supplied value.
|
void |
setLength(int len)
Sets the length of the string content.
|
String |
substring(int from)
Returns the (@code String) representation of the substring from starting index
to the end of the content array.
|
String |
substring(int from,
int to)
Returns the (@code String) representation of the substring from starting index
to the ending index-1 from the content array.
|
String |
toString()
Return a string representation.
|
void |
trimToSize()
Trims the array to the current content.
|
public StringBuilder()
public StringBuilder(int cap)
cap - initial capacityNegativeArraySizeException - if argument is less than 0public StringBuilder(String str)
str - initial contentspublic StringBuilder append(Object obj)
obj - object to appendpublic StringBuilder append(String str)
str - string appended to contentpublic StringBuilder append(StringBuffer sb)
sb - (@code StringBuffer) object containing data to appendpublic StringBuilder append(char[] str)
str - character array to be appendedpublic StringBuilder append(char[] str, int ofs, int len)
str - character array containing data to appendofs - starting index of the datalen - length of data to appendpublic StringBuilder append(boolean b)
b - boolean whose value is to be appendedpublic StringBuilder append(char c)
c - character value to appendpublic StringBuilder append(int i)
i - (@code int) value whose textual representation is to be appendedpublic StringBuilder append(long lng)
lng - (@code long) value whose textual representation is to be appendedpublic StringBuilder append(float f)
f - (@code float) value whose textual representation is to be appendedpublic StringBuilder append(double d)
d - (@code double) value whose textual representation is to be appendedpublic StringBuilder delete(int start, int end)
start - starting indexend - ending indexpublic StringBuilder deleteCharAt(int idx)
idx - index to removepublic StringBuilder replace(int start, int end, String str)
start - staring indexend - ending indexstr - string content to use as the replacementpublic StringBuilder insert(int idx, char[] arr, int ofs, int len)
idx - point within the string to insert a portion of the character arrayarr - character arrayofs - offset into the character array specifying the portion to insertlen - length of substring from the array to be insertedpublic StringBuilder insert(int ofs, Object obj)
ofs - point within the string to insert the objectobj - the object to insertpublic StringBuilder insert(int ofs, String str)
ofs - point within the string to insertstr - string to be insertedpublic StringBuilder insert(int ofs, char[] arr)
ofs - point within the string to insert the character arrayarr - character arraypublic StringBuilder insert(int ofs, boolean bool)
ofs - point within the string to insert the booleanbool - true inserts "true", false inserts "false"public StringBuilder insert(int ofs, char ch)
ofs - point within the string to insert the characterch - character to insertpublic StringBuilder insert(int ofs, int val)
ofs - point within the string to insert the numberval - int value to representpublic StringBuilder insert(int ofs, long val)
ofs - point within the string to insert the numberval - long value to representpublic StringBuilder insert(int ofs, float val)
ofs - point within the string to insert the numberval - float value to representpublic StringBuilder insert(int ofs, double val)
ofs - point within the string to insert the numberval - double value to representpublic int indexOf(String str)
str - substring to matchpublic int indexOf(String str, int from)
str - substring to matchfrom - index offset to begin searchpublic int lastIndexOf(String str)
str - substring to matchpublic int lastIndexOf(String str, int from)
str - substring to matchfrom - index offset to begin searchpublic String toString()
public int length()
public int capacity()
public void ensureCapacity(int size)
size - minimum required capacitypublic void trimToSize()
public void setLength(int len)
len - new content lengthIndexOutOfBoundsException - as necessarypublic char charAt(int index)
index - the index of the characterIndexOutOfBoundsException - as necessarypublic void getChars(int from,
int to,
char[] arr,
int start)
from - starting index for data in the content arrayto - ending index in the content arrayarr - supplied destination character arraystart - destination starting point to receive datapublic void setCharAt(int index,
char ch)
index - index in the content arraych - value to be storedpublic String substring(int from)
from - staring indexpublic String substring(int from, int to)
from - staring indexto - ending index