|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.StringBuffer
public final class StringBuffer
This class can be used to work with variable length strings of characters.
| Constructor Summary | |
|---|---|
StringBuffer()
Create a new StringBuffer with an initial capacity of 16 characters. |
|
StringBuffer(CharSequence cs)
Create a new string buffer that contains the characters of the given CharSequence. |
|
StringBuffer(int theCapacity)
Create a new StringBuffer with the given initial capacity. |
|
StringBuffer(String str)
Create a new StringBuffer that contains the given String. |
|
| Method Summary | |
|---|---|
StringBuffer |
append(boolean b)
Append a boolean. |
StringBuffer |
append(char c)
Append a character to the buffer. |
StringBuffer |
append(char[] str)
Append character-data from the given char-array. |
StringBuffer |
append(char[] str,
int offset,
int len)
Append character-data from the given char-array. |
StringBuffer |
append(CharSequence cs)
Append a character sequence to the buffer. |
StringBuffer |
append(CharSequence cs,
int start,
int end)
Append a sub-sequence of a character sequence to the buffer. |
StringBuffer |
append(double d)
Append the given double to the buffer. |
StringBuffer |
append(float f)
Append the given float to the buffer. |
StringBuffer |
append(int integerToAppend)
Append the given integer to the buffer. |
StringBuffer |
append(long longToAppend)
Append the given long to the buffer. |
StringBuffer |
append(Object obj)
Append the String representation of the given Object to this buffer. |
StringBuffer |
append(String str)
Append the given String to this buffer. |
StringBuffer |
append(StringBuffer sb)
Append the content of the given StringBuffer to this buffer. |
StringBuffer |
appendCodePoint(int a)
appendCodePoint |
int |
capacity()
The current capacity of the internal buffer. |
char |
charAt(int index)
Reads the character at teh given index. |
int |
codePointAt(int a)
codePointAt |
int |
codePointBefore(int a)
codePointBefore |
int |
codePointCount(int a,
int b)
codePointCount |
StringBuffer |
delete(int start,
int end)
delete removes characters from start to end-1 |
StringBuffer |
deleteCharAt(int index)
deleteCharAt delete the character at the specified position. |
void |
ensureCapacity(int minimumCapacity)
Ensure that (minimumCapacity - length()) characters can be appended to this buffer without allocating additional buffer. |
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Copy character-data from the internal buffer into the given buffer. |
int |
indexOf(String str)
Looks for the first occurrence of the given string. |
int |
indexOf(String str,
int fromIndex)
Looks for the first occurrence of the given string on or after the givent start index. |
StringBuffer |
insert(int offset,
boolean b)
insert the string "true" or "false" at a given position. |
StringBuffer |
insert(int offset,
char c)
insert a character at a given position. |
StringBuffer |
insert(int offset,
char[] str)
insert an array of characters at given position. |
StringBuffer |
insert(int index,
char[] str,
int offset,
int len)
insert inserts characters str[offset..offset+len-1] into this at position index. |
StringBuffer |
insert(int offset,
CharSequence cs)
Insert all characters in given CharSequence at position offset into this StringBuffer. |
StringBuffer |
insert(int index,
CharSequence cs,
int start,
int end)
insert inserts characters cs.charAt(start)..cs.charAt(end-1) into this at position index. |
StringBuffer |
insert(int offset,
double d)
insert a double converted to a string at given position. |
StringBuffer |
insert(int offset,
float f)
insert a float converted to a string at given position. |
StringBuffer |
insert(int offset,
int i)
insert an integer converted to a decimal number at given position. |
StringBuffer |
insert(int offset,
long l)
insert a long integer converted to a decimal number at given position. |
StringBuffer |
insert(int offset,
Object obj)
insert the string representation of an object at a given position. |
StringBuffer |
insert(int offset,
String str)
insert a string at a given position. |
int |
lastIndexOf(String str)
Looks for the index of the last occurrence of the given string in the buffer. |
int |
lastIndexOf(String str,
int fromIndex)
Looks for the index of the last occurrence on or before the given index. |
int |
length()
The amount of character data in this buffer. |
int |
offsetByCodePoints(int a,
int b)
offsetByCodePoints |
StringBuffer |
replace(int start,
int end,
String str)
replace replace the characters from start..end-1 with str |
StringBuffer |
reverse()
Reverse the order of the character-data in the internal buffer. |
void |
setCharAt(int index,
char ch)
Set the character at the given index.For the index the following must be true: 0 <= index < length()<=capacity() |
void |
setLength(int newLength)
Set the length of the current data in the buffer. |
CharSequence |
subSequence(int start,
int end)
Get the CharSequence begining at the start index and going up to but not including the end index. |
String |
substring(int start)
substring returns the suffix of this starting a given character position. |
String |
substring(int start,
int end)
Gets the substring starting at the start index upto but not including the end index. |
String |
toString()
Get the content of this StringBuffer as String. |
void |
trimToSize()
Reduce the storage required for the characters in this 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 theCapacity)
theCapacity - initial capacity of the internal buffer.
NegativeArraySizeException - if theCapacity < 0public StringBuffer(String str)
str - initial string.
NullPointerException - if str is nullpublic StringBuffer(CharSequence cs)
cs - the character sequence
NullPointerException - if cs is null.| Method Detail |
|---|
public CharSequence subSequence(int start,
int end)
subSequence in interface CharSequencestart - index of the first character to be included in the substring.end - index of the first character after the substring.
StringIndexOutOfBoundsException - is start is negative,
larger than length or larger than end.public int length()
toString()
was called this would be the length of the returned String. This is
different from the capacity of this buffer.
length in interface CharSequencecapacity()public int capacity()
capacity()public void ensureCapacity(int minimumCapacity)
minimumCapacity - that should be guaranteed.public void setLength(int newLength)
newLength - of data in the buffer.
IndexOutOfBoundsException - if the new length is negativepublic char charAt(int index)
charAt in interface CharSequenceindex - of the character to read.
IndexOutOfBoundsException - if index is negative or greater
or equal than length.
public void getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
srcBegin - start index in the internal buffer.srcEnd - end index in the internal buffer (not included).dst - destination buffer.dstBegin - offset to start in the destination buffer.
Nullpointerexception - if dst is null.
IndexOutOfBoundsException - if srcBegin<0, dstBegin<0,
srcBegin>srcEnd, srcEnd>length or
dstBeging+srcEnc-srcBegin>dst.length.
public void setCharAt(int index,
char ch)
0 <= index < length()<=capacity()
index - which character to set.ch - new value of the charater.
IndexOutOfBoundsException - if index < 0 or index >=
length()public StringBuffer append(Object obj)
NOTE: this method must not be synchronized since the call to obj.toString performed by String.valueOf may cause a recursive call to append(Object), which may then be detected as a potential deadlock if the Analysis cannot proof that the two StringBuffer objects are different.
obj - the Object to append.
public StringBuffer append(StringBuffer sb)
sb - the StringBuffer to append.
public StringBuffer append(String str)
str - the string to append.
public StringBuffer append(char[] str)
str - value containing the chars.
public StringBuffer append(char[] str,
int offset,
int len)
str - buffer containing the chars.offset - start index in the buffer.len - number of characters to append to this buffer.
public StringBuffer append(boolean b)
b - the boolean to append.
public StringBuffer append(char c)
append in interface Appendablec - the character to append.
public StringBuffer append(CharSequence cs)
append in interface Appendablecs - the character sequence.
public StringBuffer append(CharSequence cs,
int start,
int end)
append in interface Appendablecs - the character sequence.start - the index of the first character in cs to be appendedend - the position in cs after the last character to be appended.
StringIndexOutOfBoundsException - if start<0, start>end or
end>cs.length().public StringBuffer append(int integerToAppend)
integerToAppend - the integer to append.
public StringBuffer append(long longToAppend)
longToAppend - the long to append to the buffer.
public StringBuffer append(float f)
f - the float to append.
public StringBuffer append(double d)
d - the double to append.
public StringBuffer delete(int start,
int end)
start - the first character to deleteend - the character position after the last character to be
deleted.
StringIndexOutOfBoundsException - is start is negative,
larger than length or larger than end.public StringBuffer deleteCharAt(int index)
index - the character position
StringIndexOutOfBoundsException - is index is negative,
or larger or equal to length
public StringBuffer replace(int start,
int end,
String str)
start - the first character to be replacedend - the character position after the last character to be
replaced.str - the string to be inserted instead of the replaced characters
StringIndexOutOfBoundsException - is start is negative,
larger than length or larger than end.public String substring(int start)
start - the start position.
StringIndexOutOfBoundsException - if start is negative or
larger than length.
public String substring(int start,
int end)
start - index of the first character to be included in the substring.end - index of the first character after the substring.
StringIndexOutOfBoundsException - is start is negative,
larger than length or larger than end.
public StringBuffer insert(int index,
char[] str,
int offset,
int len)
index - the index where to insert the characters.str - the characters to be insertedoffset - the index of the first character in str to be
inserted.len - the number of characters to be inserted.
StringIndexOutOfBoundsException - is index is negative, or
index is larger or equal to length or offset is negative or len
is negative or or offset+len is larger than str.length.
public StringBuffer insert(int offset,
Object obj)
offset - the position where the string should be inserted.obj - the objects whose string representation should be
inserted.
StringIndexOutOfBoundsException - is offset is negative,
or larger than length
public StringBuffer insert(int offset,
String str)
offset - the position where the string should be inserted.str - the string to be inserted.
StringIndexOutOfBoundsException - is offset is negative,
or larger than length
public StringBuffer insert(int offset,
char[] str)
offset - the postion where the characters should be
inserted.str - the characters.
StringIndexOutOfBoundsException - is offset is negative,
or larger than length
public StringBuffer insert(int offset,
boolean b)
offset - the position where the string should be inserted.b - true for "true", false for "false.
public StringBuffer insert(int offset,
char c)
offset - the position where the character should be
inserted.c - the character.
StringIndexOutOfBoundsException - is offset is negative,
or larger than length
public StringBuffer insert(int offset,
int i)
offset - the position where the number should be inserted.i - the number.
public StringBuffer insert(int offset,
long l)
offset - the position where the number should be inserted.l - the number.
public StringBuffer insert(int offset,
float f)
offset - the position where the number should be inserted.f - the number.
public StringBuffer insert(int offset,
double d)
offset - the position where the number should be inserted.d - the number.
public StringBuffer insert(int offset,
CharSequence cs)
offset - the position the characters should be inserted at.cs - the character sequence, my be null for "null".
StringIndexOutOfBoundsException - is offset is negative,
or larger than length
public StringBuffer insert(int index,
CharSequence cs,
int start,
int end)
index - the index where to insert the characters.cs - the characters to be insertedstart - the index of the first character in cs to be
inserted.end - the index after the last character to be inserted.
StringIndexOutOfBoundsException - is index is negative, or
index is larger or equal to length or offset is negative or len
is negative or or offset+len is larger than str.length.public int indexOf(String str)
str - the string to look for.
NullPointerException - if str is null
public int indexOf(String str,
int fromIndex)
str - the string to look for.fromIndex - the index where the search starts.
NullPointerException - if str is nullpublic int lastIndexOf(String str)
str - the string to look for.
NullPointerException - if str is null
public int lastIndexOf(String str,
int fromIndex)
str - the string to look for.fromIndex - the index from which the search starts.
NullPointerException - if str is nullpublic StringBuffer reverse()
public String toString()
toString in interface CharSequencetoString in class Objectpublic void trimToSize()
public StringBuffer appendCodePoint(int a)
a -
public int codePointAt(int a)
a -
public int codePointBefore(int a)
a -
public int codePointCount(int a,
int b)
a - b -
public int offsetByCodePoints(int a,
int b)
a - b -
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||