public final class StringBuffer extends Object
Constructor and Description |
---|
StringBuffer()
Constructs a string buffer with initial capacity of 32.
|
StringBuffer(int cap)
Constructs a string buffer with the specified initial capacity.
|
StringBuffer(String str)
Constructs a string buffer initialized to the contents of the
specified string.
|
Modifier and Type | Method and Description |
---|---|
StringBuffer |
append(boolean bool)
Appends "true" or "false" boolean value to content.
|
StringBuffer |
append(char ch)
Appends character to content.
|
StringBuffer |
append(char[] arr)
Appends character array data to content.
|
StringBuffer |
append(char[] arr,
int ofs,
int len)
Append character data from array starting at offset for the defined length.
|
StringBuffer |
append(double val)
Appends the value of (@code double) to content.
|
StringBuffer |
append(float val)
Appends the value of (@code float) to content.
|
StringBuffer |
append(int val)
Appends the value of (@code int) to content.
|
StringBuffer |
append(long val)
Appends the value of (@code long) to content.
|
StringBuffer |
append(Object obj)
Append string representation of the object to content.
|
StringBuffer |
append(String str)
Appends the provided string.
|
StringBuffer |
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 idx)
Returns the (@code char) value at the specified index.
|
StringBuffer |
delete(int start,
int end)
Removes the specified range from the content array.
|
StringBuffer |
deleteCharAt(int idx)
Removes the character from the content sequence.
|
void |
ensureCapacity(int cap)
Make sure that the character array is large enough to store
the specified number of characters.
|
void |
getChars(int start,
int end,
char[] arr,
int ofs)
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.
|
StringBuffer |
insert(int ofs,
boolean bool)
Inserts "true" or "false" into the string at the specified offset based upon a boolean value.
|
StringBuffer |
insert(int ofs,
char ch)
Inserts the a character into the string at the specified offset.
|
StringBuffer |
insert(int ofs,
char[] arr)
Inserts the character array into the string at the specified offset.
|
StringBuffer |
insert(int idx,
char[] arr,
int ofs,
int len)
Inserts a subset of a character array into the string at the specified offset.
|
StringBuffer |
insert(int ofs,
double val)
Inserts the string representation of a double value into the string at the specified offset.
|
StringBuffer |
insert(int ofs,
float val)
Inserts the string representation of a float value into the string at the specified offset.
|
StringBuffer |
insert(int ofs,
int val)
Inserts the string representation of a int value into the string at the specified offset.
|
StringBuffer |
insert(int ofs,
long val)
Inserts the string representation of a long value into the string at the specified offset.
|
StringBuffer |
insert(int ofs,
Object obj)
Inserts a string representation of the object into the string at the specified offset.
|
StringBuffer |
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
|
StringBuffer |
replace(int start,
int end,
String str)
Replaces a section in the content sequence.
|
void |
setCharAt(int idx,
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 start)
Returns the balance of the string from a specified starting index.
|
String |
substring(int start,
int end)
Returns a portion of the string.
|
String |
toString()
Returns a a new copy of the string.
|
void |
trimToSize()
Trims the array to the current content.
|
public StringBuffer()
public StringBuffer(int cap)
cap
- the initial capacity.NegativeArraySizeException
- if the argument is less than 0public StringBuffer(String str)
str
- initial contentspublic int length()
public int capacity()
public void ensureCapacity(int cap)
cap
- minimum required capacitypublic void trimToSize()
public void setLength(int len)
len
- new content lengthpublic char charAt(int idx)
idx
- the index of the characterpublic void getChars(int start, int end, char[] arr, int ofs)
start
- starting index for data in the content arrayend
- ending index in the content arrayarr
- supplied destination character arrayofs
- destination starting point to receive datapublic void setCharAt(int idx, char ch)
idx
- index in the content arraych
- value to be storedpublic StringBuffer append(Object obj)
obj
- object to appendpublic StringBuffer append(String str)
str
- string appended to contentpublic StringBuffer append(StringBuffer sb)
sb
- (@code StringBuffer) object containing data to appendpublic StringBuffer append(char[] arr)
arr
- character array to be appendedpublic StringBuffer append(char[] arr, int ofs, int len)
arr
- character array containing data to appendofs
- starting index of the datalen
- length of data to appendpublic StringBuffer append(boolean bool)
bool
- boolean whose value is to be appendedpublic StringBuffer append(char ch)
ch
- character value to appendpublic StringBuffer append(int val)
val
- (@code int) value whose textual representation is to be appendedpublic StringBuffer append(long val)
val
- (@code long) value whose textual representation is to be appendedpublic StringBuffer append(float val)
val
- (@code float) value whose textual representation is to be appendedpublic StringBuffer append(double val)
val
- (@code double) value whose textual representation is to be appendedpublic StringBuffer delete(int start, int end)
start
- starting indexend
- ending indexpublic StringBuffer deleteCharAt(int idx)
idx
- index to removepublic StringBuffer replace(int start, int end, String str)
start
- staring indexend
- ending indexstr
- string content to use as the replacementpublic String substring(int start)
start
- starting index of the substringpublic String substring(int start, int end)
start
- starting index of the substringend
- index following the substring (excluded)public StringBuffer 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 StringBuffer insert(int ofs, Object obj)
ofs
- point within the string to insert the objectobj
- the object to insertpublic StringBuffer insert(int ofs, String str)
ofs
- point within the string to insertstr
- string to be insertedpublic StringBuffer insert(int ofs, char[] arr)
ofs
- point within the string to insert the character arrayarr
- character arraypublic StringBuffer insert(int ofs, boolean bool)
ofs
- point within the string to insert the booleanbool
- true inserts "true", false inserts "false"public StringBuffer insert(int ofs, char ch)
ofs
- point within the string to insert the characterch
- character to insertpublic StringBuffer insert(int ofs, int val)
ofs
- point within the string to insert the numberval
- int value to representpublic StringBuffer insert(int ofs, long val)
ofs
- point within the string to insert the numberval
- long value to representpublic StringBuffer insert(int ofs, float val)
ofs
- point within the string to insert the numberval
- float value to representpublic StringBuffer 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()