|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | 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()to concatenate multiple strings together. In the code shown, the compiler generates references to the StringBuffer class to append the objects together.
As with all classes in the java.lang package, you can't reference the StringBuffer class using the full specifier of java.lang.StringBuffer. The java.lang package is implicitly imported. Instead, you should simply access the StringBuffer like this:
StringBuffer sb = new StringBuffer(s);
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 buffer. |
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. |
StringBuffer |
delete(int start,
int end)
Removes the characters in a substring of this StringBuffer .
|
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. |
int |
length()
Returns the length (character count) of the buffer. |
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 |
equals,
getClass,
hashCode,
notify,
wait,
wait |
Constructor Detail |
public StringBuffer()
public StringBuffer(int length)
length
- the initial lengthpublic StringBuffer(String str)
str
- the initial buffer of the bufferMethod Detail |
public int length()
public int capacity()
public void ensureCapacity(int minimumCapacity)
minimumCapacity
- the minimum desired capacity in characterspublic void setLength(int newLength)
newLength
- the new length of the bufferpublic char charAt(int index)
index
- the index of the desired characterpublic 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 dstpublic StringBuffer append(Object obj)
obj
- the object to be appendedpublic StringBuffer append(String str)
str
- the String to be appendedpublic StringBuffer append(char[] str)
str
- the characters to be appendedpublic StringBuffer append(char[] str, int offset, int len)
str
- the characters to be appendedoffset
- where to startlen
- the number of characters to addpublic StringBuffer append(boolean b)
b
- the boolean to be appendedpublic StringBuffer append(char c)
ch
- the character to be appendedpublic StringBuffer append(int i)
i
- the integer to be appendedpublic StringBuffer append(long l)
l
- the long to be appendedpublic StringBuffer append(float f)
f
- the float to be appendedpublic StringBuffer append(double d)
d
- the double to be appendedpublic String toString()
public StringBuffer delete(int start, int end)
StringBuffer
.
The substring begins at the specified start
and extends to
the character at index end - 1
or to the end of the
StringBuffer
if no such character exists. If
start
is equal to end
, no changes are made.
If any paramter goes beyond limits, it is enforced into limits.
If start > end, the string is emptied;
Returns this
StringBuffer.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |