| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
StringBuilder sb = new StringBuilder();
Based on 98 examples
public final class StringBuilder extends AbstractStringBuilder implements Serializable, CharSequence
A mutable sequence of characters. This class provides an API compatible
with StringBuffer
, but with no guarantee of synchronization.
This class is designed for use as a drop-in replacement for
StringBuffer
in places where the string buffer was being
used by a single thread (as is generally the case). Where possible,
it is recommended that this class be used in preference to
StringBuffer
as it will be faster under most implementations.
The principal operations on a StringBuilder
are the
append
and insert
methods, which are
overloaded so as to accept data of any type. Each effectively
converts a given datum to a string and then appends or inserts the
characters of that string to the string builder. The
append
method always adds these characters at the end
of the builder; the insert
method adds the characters at
a specified point.
For example, if z
refers to a string builder object
whose current contents are "start
", then
the method call z.append("le")
would cause the string
builder to contain "startle
", whereas
z.insert(4, "le")
would alter the string builder to
contain "starlet
".
In general, if sb refers to an instance of a StringBuilder
,
then sb.append(x)
has the same effect as
sb.insert(sb.length(), x)
.
Every string builder has a capacity. As long as the length of the
character sequence contained in the string builder does not exceed
the capacity, it is not necessary to allocate a new internal
buffer. If the internal buffer overflows, it is automatically made larger.
Instances of StringBuilder
are not safe for
use by multiple threads. If such synchronization is required then it is
recommended that {@link java.lang.StringBuffer} be used.
Constructor Summary | |
---|---|
Constructs a string builder with no characters in it and an initial capacity of 16 characters. |
|
Constructs a string builder that contains the same characters as the specified CharSequence .
|
|
StringBuilder(int capacity) Constructs a string builder with no characters in it and an initial capacity specified by the capacity argument.
|
|
StringBuilder(String str) Constructs a string builder initialized to the contents of the specified string. |
Constructor Detail |
---|
public StringBuilder()
public StringBuilder(CharSequence seq)
CharSequence
. The initial capacity of
the string builder is 16
plus the length of the
CharSequence
argument.
seq
- the sequence to copy.public StringBuilder(int capacity)
capacity
argument.
capacity
- the initial capacity.public StringBuilder(String str)
16
plus the length of the string argument.
str
- the initial contents of the buffer.Method Detail |
---|
public StringBuilder append(boolean b)
append
in class AbstractStringBuilder
b
public StringBuilder append(char c)
append
in class AbstractStringBuilder
c
public StringBuilder append(CharSequence s)
append
in class AbstractStringBuilder
s
public StringBuilder append(CharSequence s, int start, int end)
append
in class AbstractStringBuilder
s
start
end
public StringBuilder append(char[] str)
append
in class AbstractStringBuilder
str
public StringBuilder append(char[] str, int offset, int len)
append
in class AbstractStringBuilder
str
offset
len
public StringBuilder append(double d)
append
in class AbstractStringBuilder
d
public StringBuilder append(float f)
append
in class AbstractStringBuilder
f
public StringBuilder append(int i)
append
in class AbstractStringBuilder
i
public StringBuilder append(long lng)
append
in class AbstractStringBuilder
lng
public StringBuilder append(Object obj)
append
in class AbstractStringBuilder
obj
public StringBuilder append(String str)
append
in class AbstractStringBuilder
str
public StringBuilder append(StringBuffer sb)
The characters of the StringBuffer argument are appended, in order, to this sequence, increasing the length of this sequence by the length of the argument. If sb is null, then the four characters "null" are appended to this sequence.
Let n be the length of this character sequence just prior to
execution of the append method. Then the character at index
k in the new character sequence is equal to the character at
index k in the old character sequence, if k is less than
n; otherwise, it is equal to the character at index k-n
in the argument sb
.
append
in class AbstractStringBuilder
sb
- the StringBuffer to append.public StringBuilder appendCodePoint(int codePoint)
appendCodePoint
in class AbstractStringBuilder
codePoint
public StringBuilder delete(int start, int end)
delete
in class AbstractStringBuilder
start
end
public StringBuilder deleteCharAt(int index)
deleteCharAt
in class AbstractStringBuilder
index
public int indexOf(String str)
indexOf
in class AbstractStringBuilder
str
public int indexOf(String str, int fromIndex)
indexOf
in class AbstractStringBuilder
str
fromIndex
public StringBuilder insert(int offset, boolean b)
insert
in class AbstractStringBuilder
offset
b
public StringBuilder insert(int offset, char c)
insert
in class AbstractStringBuilder
offset
c
public StringBuilder insert(int dstOffset, CharSequence s)
insert
in class AbstractStringBuilder
dstOffset
s
public StringBuilder insert(int dstOffset, CharSequence s, int start, int end)
insert
in class AbstractStringBuilder
dstOffset
s
start
end
public StringBuilder insert(int offset, char[] str)
insert
in class AbstractStringBuilder
offset
str
public StringBuilder insert(int index, char[] str, int offset, int len)
insert
in class AbstractStringBuilder
index
str
offset
len
public StringBuilder insert(int offset, double d)
insert
in class AbstractStringBuilder
offset
d
public StringBuilder insert(int offset, float f)
insert
in class AbstractStringBuilder
offset
f
public StringBuilder insert(int offset, int i)
insert
in class AbstractStringBuilder
offset
i
public StringBuilder insert(int offset, long l)
insert
in class AbstractStringBuilder
offset
l
public StringBuilder insert(int offset, Object obj)
insert
in class AbstractStringBuilder
offset
obj
public StringBuilder insert(int offset, String str)
insert
in class AbstractStringBuilder
offset
str
public int lastIndexOf(String str)
lastIndexOf
in class AbstractStringBuilder
str
public int lastIndexOf(String str, int fromIndex)
lastIndexOf
in class AbstractStringBuilder
str
fromIndex
public StringBuilder replace(int start, int end, String str)
replace
in class AbstractStringBuilder
start
end
str
public StringBuilder reverse()
reverse
in class AbstractStringBuilder
public String toString()
toString
in class AbstractStringBuilder
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |