public class StringBuilder extends Object implements CharSequence, Appendable
Constructor and Description |
---|
StringBuilder() |
StringBuilder(CharSequence seq) |
StringBuilder(int length) |
StringBuilder(String aString) |
Modifier and Type | Method and Description |
---|---|
StringBuilder |
append(boolean aBoolean) |
StringBuilder |
append(char aChar)
Appends the Unicode character, c, to this
Appendable
object. |
StringBuilder |
append(char[] c) |
StringBuilder |
append(char[] c,
int off,
int len) |
StringBuilder |
append(CharSequence cs)
Appends the specified sequence of Unicode characters to this
Appendable object. |
StringBuilder |
append(CharSequence cs,
int start,
int end)
Appends the specified subsequence of Unicode characters to this
Appendable object, starting and ending at the specified
positions within the sequence. |
StringBuilder |
append(double aDouble) |
StringBuilder |
append(float aFloat) |
StringBuilder |
append(int i) |
StringBuilder |
append(long aLong) |
StringBuilder |
append(Object aObject) |
StringBuilder |
append(String s) |
StringBuilder |
append(StringBuffer sb) |
StringBuilder |
appendCodePoint(int cp) |
int |
capacity() |
char |
charAt(int i)
Returns the character at the given index.
|
StringBuilder |
delete(int start,
int end) |
StringBuilder |
deleteCharAt(int index) |
void |
ensureCapacity(int minCapacity) |
void |
getChars(int start,
int end,
char[] dst,
int dstStart)
Retrieves the contents of the StringBuilder in the form of an array of characters.
|
int |
indexOf(String str) |
int |
indexOf(String str,
int fromIndex) |
StringBuilder |
insert(int offset,
char[] data)
Insert the
char[] argument into this
StringBuffer . |
StringBuilder |
insert(int offset,
char[] str,
int str_offset,
int len)
Insert a subarray of the
char[] argument into this
StringBuffer . |
StringBuilder |
insert(int offset,
Object obj)
Insert the
String value of the argument into this
StringBuffer . |
StringBuilder |
insert(int offset,
String str)
Insert the
String argument into this
StringBuffer . |
int |
lastIndexOf(String str) |
int |
lastIndexOf(String str,
int fromIndex) |
int |
length()
Returns the length of the sequence.
|
StringBuilder |
replace(int start,
int end,
String str)
Replace characters between index
start (inclusive) and
end (exclusive) with str . |
StringBuilder |
reverse()
Reverse the characters in this StringBuffer.
|
void |
setCharAt(int i,
char ch) |
void |
setLength(int newLen) |
CharSequence |
subSequence(int start,
int end)
Returns a new
CharSequence of the indicated range. |
String |
substring(int start) |
String |
substring(int start,
int end) |
String |
toString()
Returns the complete
CharSequence as a String . |
void |
trimToSize() |
public StringBuilder()
public StringBuilder(CharSequence seq)
public StringBuilder(int length)
public StringBuilder(String aString)
public StringBuilder append(boolean aBoolean)
public StringBuilder append(char aChar)
Appendable
Appendable
object.append
in interface Appendable
aChar
- the character to append.public StringBuilder append(char[] c)
public StringBuilder append(char[] c, int off, int len)
public StringBuilder append(CharSequence cs)
Appendable
Appendable
object. The entire sequence may not
be appended, if constrained by the underlying implementation.
For example, a buffer may reach its size limit before the entire
sequence is appended.append
in interface Appendable
cs
- the character sequence to append. If seq is null,
then the string "null" (the string representation of null)
is appended.public StringBuilder append(CharSequence cs, int start, int end)
Appendable
Appendable
object, starting and ending at the specified
positions within the sequence. The entire sequence may not
be appended, if constrained by the underlying implementation.
For example, a buffer may reach its size limit before the entire
sequence is appended. The behaviour of this method matches the
behaviour of append(seq.subSequence(start,end))
when
the sequence is not null.append
in interface Appendable
cs
- the character sequence to append. If seq is null,
then the string "null" (the string representation of null)
is appended.start
- the index of the first Unicode character to use from
the sequence.end
- the index of the last Unicode character to use from the
sequence.public StringBuilder append(double aDouble)
public StringBuilder append(float aFloat)
public StringBuilder append(int i)
public StringBuilder append(long aLong)
public StringBuilder append(Object aObject)
public StringBuilder append(String s)
public StringBuilder append(StringBuffer sb)
public StringBuilder appendCodePoint(int cp)
public int capacity()
public char charAt(int i)
CharSequence
charAt
in interface CharSequence
i
- the index to retrieve frompublic StringBuilder delete(int start, int end)
public StringBuilder deleteCharAt(int index)
public void ensureCapacity(int minCapacity)
public void getChars(int start, int end, char[] dst, int dstStart)
public int indexOf(String str)
public int indexOf(String str, int fromIndex)
public StringBuilder insert(int offset, char[] data)
char[]
argument into this
StringBuffer
.offset
- the place to insert in this bufferdata
- the char[]
to insertStringBuffer
NullPointerException
- if data
is null
StringIndexOutOfBoundsException
- if offset is out of boundsinsert(int, char[], int, int)
public StringBuilder insert(int offset, char[] str, int str_offset, int len)
char[]
argument into this
StringBuffer
.offset
- the place to insert in this bufferstr
- the char[]
to insertstr_offset
- the index in str
to start inserting fromlen
- the number of characters to insertStringBuffer
NullPointerException
- if str
is null
StringIndexOutOfBoundsException
- if any index is out of boundspublic StringBuilder insert(int offset, Object obj)
String
value of the argument into this
StringBuffer
. Uses String.valueOf()
to convert
to String
.offset
- the place to insert in this bufferobj
- the Object
to convert and insertStringBuffer
StringIndexOutOfBoundsException
- if offset is out of boundsString.valueOf(Object)
public StringBuilder insert(int offset, String str)
String
argument into this
StringBuffer
. If str is null, the String "null" is used
instead.offset
- the place to insert in this bufferstr
- the String
to insertStringBuffer
StringIndexOutOfBoundsException
- if offset is out of boundspublic int lastIndexOf(String str)
public int lastIndexOf(String str, int fromIndex)
public int length()
CharSequence
length
in interface CharSequence
public StringBuilder replace(int start, int end, String str)
start
(inclusive) and
end
(exclusive) with str
. If end
is larger than the size of this StringBuffer, all characters after
start
are replaced.start
- the beginning index of characters to delete (inclusive)end
- the ending index of characters to delete (exclusive)str
- the new String
to insertStringBuffer
StringIndexOutOfBoundsException
- if start or end are out of boundsNullPointerException
- if str is nullpublic StringBuilder reverse()
StringBuffer
public void setCharAt(int i, char ch)
public void setLength(int newLen)
public CharSequence subSequence(int start, int end)
CharSequence
CharSequence
of the indicated range.subSequence
in interface CharSequence
start
- the start index (inclusive)end
- the end index (exclusive)public String substring(int start)
public String substring(int start, int end)
public String toString()
CharSequence
CharSequence
as a String
.
Classes that implement this interface should return a String
which contains only the characters in the sequence in the correct order.toString
in interface CharSequence
toString
in class Object
public void trimToSize()