|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--java.lang.StringBuffer
This Class is a growable buffer for characters. It is mainly used to create Strings. The compiler uses it to implement the "+" operator. For example:
"a" + 4 + "c"is compiled to:
new StringBuffer().append("a").append(4).append("c").toString()
Note that the method toString() does not create a copy of the internal buffer. Instead
the buffer is marked as shared. Any further changes to the buffer will
cause a copy to be made.
String,
ByteArrayOutputStream| Constructor Summary | |
StringBuffer()
Constructs an empty String buffer. |
|
StringBuffer(int length)
Constructs an empty String buffer with the specified initial length. |
|
StringBuffer(String str)
Constructs a String buffer with the specified initial value. |
|
| Method Summary | |
StringBuffer |
append(boolean b)
Appends a boolean to the end of this buffer. |
StringBuffer |
append(char c)
Appends a character to the end of this buffer. |
StringBuffer |
append(char[] str)
Appends an array of characters to the end of this buffer. |
StringBuffer |
append(char[] str,
int offset,
int len)
Appends a part of an array of characters to the end of this buffer. |
StringBuffer |
append(double d)
Appends a double to the end of this buffer. |
StringBuffer |
append(float f)
Appends a float to the end of this buffer. |
StringBuffer |
append(int i)
Appends an integer to the end of this buffer. |
StringBuffer |
append(long l)
Appends a long to the end of this buffer. |
StringBuffer |
append(Object obj)
Appends an object to the end of this buffer. |
StringBuffer |
append(String str)
Appends a String to the end of this buffer. |
int |
capacity()
Returns the current capacity of the String buffer. |
char |
charAt(int index)
Returns the character at the specified index. |
void |
ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum. |
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Copies the characters of the specified substring (determined by srcBegin and srcEnd) into the character array, starting at the array's dstBegin location. |
StringBuffer |
insert(int offset,
boolean b)
Inserts a boolean into the String buffer. |
StringBuffer |
insert(int offset,
char c)
Inserts a character into the String buffer. |
StringBuffer |
insert(int offset,
char[] str)
Inserts an array of characters into the String buffer. |
StringBuffer |
insert(int offset,
double d)
Inserts a double into the String buffer. |
StringBuffer |
insert(int offset,
float f)
Inserts a float into the String buffer. |
StringBuffer |
insert(int offset,
int i)
Inserts an integer into the String buffer. |
StringBuffer |
insert(int offset,
long l)
Inserts a long into the String buffer. |
StringBuffer |
insert(int offset,
Object obj)
Inserts an object into the String buffer. |
StringBuffer |
insert(int offset,
String str)
Inserts a String into the String buffer. |
int |
length()
Returns the length (character count) of the buffer. |
StringBuffer |
reverse()
Reverse the order of the characters in the String buffer. |
void |
setCharAt(int index,
char ch)
Changes the character at the specified index to be ch. |
void |
setLength(int newLength)
Sets the length of the String. |
String |
toString()
Converts to a String representing the data in the buffer. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public StringBuffer()
public StringBuffer(int length)
length - the initial lengthpublic StringBuffer(String str)
str - the initial value of the buffer| Method Detail |
public int length()
public int capacity()
public void ensureCapacity(int minimumCapacity)
minimumCapacity - the minimum desired capacitypublic void setLength(int newLength)
newLength - the new length of the buffer
StringIndexOutOfBoundsException - If the length is invalid.public char charAt(int index)
index - the index of the desired character
StringIndexOutOfBoundsException - If the index is invalid.
public void getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
srcBegin - begin copy at this offset in the StringsrcEnd - stop copying at this offset in the Stringdst - the array to copy the data intodstBegin - offset into dst
StringIndexOutOfBoundsException - If there is an invalid index into the buffer.
public void setCharAt(int index,
char ch)
index - the index of the characterch - the new character
StringIndexOutOfBoundsException - If the index is invalid.public StringBuffer append(Object obj)
obj - the object to be appended
public StringBuffer append(String str)
str - the String to be appended
public StringBuffer append(char[] str)
str - the characters to be appended
public StringBuffer append(char[] str,
int offset,
int len)
str - the characters to be appendedoffset - where to startlen - the number of characters to add
public StringBuffer append(boolean b)
b - the boolean to be appended
public StringBuffer append(char c)
public StringBuffer append(int i)
i - the integer to be appended
public StringBuffer append(long l)
l - the long to be appended
public StringBuffer append(float f)
f - the float to be appended
public StringBuffer append(double d)
d - the double to be appended
public StringBuffer insert(int offset,
Object obj)
offset - the offset at which to insertobj - the object to insert
StringIndexOutOfBoundsException - If the offset is invalid.
public StringBuffer insert(int offset,
String str)
offset - the offset at which to insertstr - the String to insert
StringIndexOutOfBoundsException - If the offset is invalid.
public StringBuffer insert(int offset,
char[] str)
offset - the offset at which to insertstr - the characters to insert
StringIndexOutOfBoundsException - If the offset is invalid.
public StringBuffer insert(int offset,
boolean b)
offset - the offset at which to insertb - the boolean to insert
StringIndexOutOfBoundsException - If the offset is invalid.
public StringBuffer insert(int offset,
char c)
offset - the offset at which to insert
StringIndexOutOfBoundsException - If the offset invalid.
public StringBuffer insert(int offset,
int i)
offset - the offset at which to inserti - the integer to insert
StringIndexOutOfBoundsException - If the offset is invalid.
public StringBuffer insert(int offset,
long l)
offset - the offset at which to insertl - the long to insert
StringIndexOutOfBoundsException - If the offset is invalid.
public StringBuffer insert(int offset,
float f)
offset - the offset at which to insertf - the float to insert
StringIndexOutOfBoundsException - If the offset is invalid.
public StringBuffer insert(int offset,
double d)
offset - the offset at which to insertd - the double to insert
StringIndexOutOfBoundsException - If the offset is invalid.public StringBuffer reverse()
public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||