public final class CStringBuilder extends Object
sequence of characters
for use in creating
and modifying Strings. This class is intended as a direct replacement of
StringBuffer
for non-concurrent use; unlike StringBuffer
this
class is not synchronized for thread safety.
The majority of the modification methods on this class return StringBuilder
, so that, like StringBuffer
s, they can be used in
chaining method calls together. For example, new StringBuilder("One
should ").append("always strive ").append("to achieve Harmony")
.
CharSequence
,
Appendable
,
StringBuffer
,
String
Constructor and Description |
---|
CStringBuilder()
Deprecated.
Constructs an instance with an initial capacity of
16 . |
CStringBuilder(int capacity)
Deprecated.
Constructs an instance with the specified capacity.
|
CStringBuilder(String str)
Deprecated.
Constructs an instance that's initialized with the contents of the
specified
String . |
Modifier and Type | Method and Description |
---|---|
CStringBuilder |
append(boolean b)
Deprecated.
Appends the string representation of the specified
boolean value. |
CStringBuilder |
append(char c)
Deprecated.
Appends the string representation of the specified
char value. |
CStringBuilder |
append(char[] ch)
Deprecated.
Appends the string representation of the specified
char[] . |
CStringBuilder |
append(char[] str,
int offset,
int len)
Deprecated.
Appends the string representation of the specified subset of the
char[] . |
CStringBuilder |
append(double d)
Deprecated.
Appends the string representation of the specified
double value. |
CStringBuilder |
append(float f)
Deprecated.
Appends the string representation of the specified
float value. |
CStringBuilder |
append(int i)
Deprecated.
Appends the string representation of the specified
int value. |
CStringBuilder |
append(long lng)
Deprecated.
Appends the string representation of the specified
long value. |
CStringBuilder |
append(Object obj)
Deprecated.
Appends the string representation of the specified
Object . |
CStringBuilder |
append(String str)
Deprecated.
Appends the contents of the specified string.
|
CStringBuilder |
appendCodePoint(int codePoint)
Deprecated.
Appends the encoded Unicode code point.
|
int |
capacity()
Returns the number of characters that can be held without growing.
|
char |
charAt(int index)
Retrieves the character at the
index . |
int |
codePointAt(int index)
Retrieves the Unicode code point value at the
index . |
int |
codePointBefore(int index)
Retrieves the Unicode code point value that precedes the
index . |
int |
codePointCount(int beginIndex,
int endIndex)
Calculates the number of Unicode code points between
beginIndex
and endIndex . |
CStringBuilder |
delete(int start,
int end)
Deprecated.
Deletes a sequence of characters specified by
start and end . |
CStringBuilder |
deleteCharAt(int index)
Deprecated.
Deletes the character at the specified index.
|
void |
ensureCapacity(int min)
Ensures that this object has a minimum capacity available before
requiring the internal buffer to be enlarged.
|
void |
getChars(int start,
int end,
char[] dest,
int destStart)
Copies the requested sequence of characters to the
char[] passed
starting at destStart . |
int |
indexOf(String string)
Searches for the first index of the specified character.
|
int |
indexOf(String subString,
int start)
Searches for the index of the specified character.
|
CStringBuilder |
insert(int offset,
boolean b)
Deprecated.
Inserts the string representation of the specified
boolean value
at the specified offset . |
CStringBuilder |
insert(int offset,
char c)
Deprecated.
Inserts the string representation of the specified
char value at
the specified offset . |
CStringBuilder |
insert(int offset,
char[] ch)
Deprecated.
Inserts the string representation of the specified
char[] at the
specified offset . |
CStringBuilder |
insert(int offset,
char[] str,
int strOffset,
int strLen)
Deprecated.
Inserts the string representation of the specified subsequence of the
char[] at the specified offset . |
CStringBuilder |
insert(int offset,
double d)
Deprecated.
Inserts the string representation of the specified
double value
at the specified offset . |
CStringBuilder |
insert(int offset,
float f)
Deprecated.
Inserts the string representation of the specified
float value at
the specified offset . |
CStringBuilder |
insert(int offset,
int i)
Deprecated.
Inserts the string representation of the specified
int value at
the specified offset . |
CStringBuilder |
insert(int offset,
long l)
Deprecated.
Inserts the string representation of the specified
long value at
the specified offset . |
CStringBuilder |
insert(int offset,
Object obj)
Deprecated.
Inserts the string representation of the specified
Object at the
specified offset . |
CStringBuilder |
insert(int offset,
String str)
Deprecated.
Inserts the specified string at the specified
offset . |
int |
lastIndexOf(String string)
Searches for the last index of the specified character.
|
int |
lastIndexOf(String subString,
int start)
Searches for the index of the specified character.
|
int |
length()
The current length.
|
int |
offsetByCodePoints(int index,
int codePointOffset)
Returns the index that is offset
codePointOffset code points from
index . |
CStringBuilder |
replace(int start,
int end,
String str)
Deprecated.
Replaces the specified subsequence in this builder with the specified
string.
|
CStringBuilder |
reverse()
Deprecated.
Reverses the order of characters in this builder.
|
void |
setCharAt(int index,
char ch)
Sets the character at the
index . |
void |
setLength(int length)
Sets the current length to a new value.
|
String |
substring(int start)
Returns the String value of the subsequence from the
start index
to the current end. |
String |
substring(int start,
int end)
Returns the String value of the subsequence from the
start index
to the end index. |
String |
toString()
Deprecated.
Returns the contents of this builder.
|
void |
trimToSize()
Trims off any extra capacity beyond the current length.
|
public CStringBuilder()
16
.capacity()
public CStringBuilder(int capacity)
capacity
- the initial capacity to use.NegativeArraySizeException
- if the specified capacity
is negative.capacity()
public CStringBuilder(String str)
String
. The capacity of the new builder will be the
length of the String
plus 16.str
- the String
to copy into the builder.NullPointerException
- if str
is null
.public CStringBuilder append(boolean b)
boolean
value.
The boolean
value is converted to a String according to the rule
defined by String.valueOf(boolean)
.b
- the boolean
value to append.String.valueOf(boolean)
public CStringBuilder append(char c)
char
value.
The char
value is converted to a string according to the rule
defined by String.valueOf(char)
.c
- the char
value to append.String.valueOf(char)
public CStringBuilder append(int i)
int
value. The
int
value is converted to a string according to the rule defined
by String.valueOf(int)
.i
- the int
value to append.String.valueOf(int)
public CStringBuilder append(long lng)
long
value.
The long
value is converted to a string according to the rule
defined by String.valueOf(long)
.lng
- the long
value.String.valueOf(long)
public CStringBuilder append(float f)
float
value.
The float
value is converted to a string according to the rule
defined by String.valueOf(float)
.f
- the float
value to append.String.valueOf(float)
public CStringBuilder append(double d)
double
value.
The double
value is converted to a string according to the rule
defined by String.valueOf(double)
.d
- the double
value to append.String.valueOf(double)
public CStringBuilder append(Object obj)
Object
.
The Object
value is converted to a string according to the rule
defined by String.valueOf(Object)
.obj
- the Object
to append.String.valueOf(Object)
public CStringBuilder append(String str)
null
, then the string "null"
is appended.str
- the string to append.public CStringBuilder append(char[] ch)
char[]
.
The char[]
is converted to a string according to the rule
defined by String.valueOf(char[])
.ch
- the char[]
to append..String.valueOf(char[])
public CStringBuilder append(char[] str, int offset, int len)
char[]
. The char[]
value is converted to a String according to
the rule defined by String.valueOf(char[],int,int)
.str
- the char[]
to append.offset
- the inclusive offset index.len
- the number of characters.ArrayIndexOutOfBoundsException
- if offset
and len
do not specify a valid
subsequence.String.valueOf(char[],int,int)
public CStringBuilder appendCodePoint(int codePoint)
char[]
as defined by Character.toChars(int)
.codePoint
- the Unicode code point to encode and append.Character.toChars(int)
public CStringBuilder delete(int start, int end)
start
and end
. Shifts any remaining characters to the left.start
- the inclusive start index.end
- the exclusive end index.StringIndexOutOfBoundsException
- if start
is less than zero, greater than the current
length or greater than end
.public CStringBuilder deleteCharAt(int index)
index
- the index of the character to delete.StringIndexOutOfBoundsException
- if index
is less than zero or is greater than or
equal to the current length.public CStringBuilder insert(int offset, boolean b)
boolean
value
at the specified offset
. The boolean
value is converted
to a string according to the rule defined by
String.valueOf(boolean)
.offset
- the index to insert at.b
- the boolean
value to insert.StringIndexOutOfBoundsException
- if offset
is negative or greater than the current
length
.String.valueOf(boolean)
public CStringBuilder insert(int offset, char c)
char
value at
the specified offset
. The char
value is converted to a
string according to the rule defined by String.valueOf(char)
.offset
- the index to insert at.c
- the char
value to insert.IndexOutOfBoundsException
- if offset
is negative or greater than the current
length()
.String.valueOf(char)
public CStringBuilder insert(int offset, int i)
int
value at
the specified offset
. The int
value is converted to a
String according to the rule defined by String.valueOf(int)
.offset
- the index to insert at.i
- the int
value to insert.StringIndexOutOfBoundsException
- if offset
is negative or greater than the current
length()
.String.valueOf(int)
public CStringBuilder insert(int offset, long l)
long
value at
the specified offset
. The long
value is converted to a
String according to the rule defined by String.valueOf(long)
.offset
- the index to insert at.l
- the long
value to insert.StringIndexOutOfBoundsException
- if offset
is negative or greater than the current
{code length()}.String.valueOf(long)
public CStringBuilder insert(int offset, float f)
float
value at
the specified offset
. The float
value is converted to a
string according to the rule defined by String.valueOf(float)
.offset
- the index to insert at.f
- the float
value to insert.StringIndexOutOfBoundsException
- if offset
is negative or greater than the current
length()
.String.valueOf(float)
public CStringBuilder insert(int offset, double d)
double
value
at the specified offset
. The double
value is converted
to a String according to the rule defined by
String.valueOf(double)
.offset
- the index to insert at.d
- the double
value to insert.StringIndexOutOfBoundsException
- if offset
is negative or greater than the current
length()
.String.valueOf(double)
public CStringBuilder insert(int offset, Object obj)
Object
at the
specified offset
. The Object
value is converted to a
String according to the rule defined by String.valueOf(Object)
.offset
- the index to insert at.obj
- the Object
to insert.StringIndexOutOfBoundsException
- if offset
is negative or greater than the current
length()
.String.valueOf(Object)
public CStringBuilder insert(int offset, String str)
offset
. If the
specified string is null, then the String "null"
is inserted.offset
- the index to insert at.str
- the String
to insert.StringIndexOutOfBoundsException
- if offset
is negative or greater than the current
length()
.public CStringBuilder insert(int offset, char[] ch)
char[]
at the
specified offset
. The char[]
value is converted to a
String according to the rule defined by String.valueOf(char[])
.offset
- the index to insert at.ch
- the char[]
to insert.StringIndexOutOfBoundsException
- if offset
is negative or greater than the current
length()
.String.valueOf(char[])
public CStringBuilder insert(int offset, char[] str, int strOffset, int strLen)
char[]
at the specified offset
. The char[]
value
is converted to a String according to the rule defined by
String.valueOf(char[],int,int)
.offset
- the index to insert at.str
- the char[]
to insert.strOffset
- the inclusive index.strLen
- the number of characters.StringIndexOutOfBoundsException
- if offset
is negative or greater than the current
length()
, or strOffset
and strLen
do
not specify a valid subsequence.String.valueOf(char[],int,int)
public CStringBuilder replace(int start, int end, String str)
start
- the inclusive begin index.end
- the exclusive end index.str
- the replacement string.StringIndexOutOfBoundsException
- if start
is negative, greater than the current
length()
or greater than end
.NullPointerException
- if str
is null
.public CStringBuilder reverse()
public String toString()
public int capacity()
ensureCapacity(int)
,
length()
public char charAt(int index)
index
.index
- the index of the character to retrieve.IndexOutOfBoundsException
- if index
is negative or greater than or equal to the
current length()
.public void ensureCapacity(int min)
minimumCapacity
is larger than the current
capacity()
, then the capacity will be increased to the largest
value of either the minimumCapacity
or the current capacity
multiplied by two plus two. Although this is the general policy, there is
no guarantee that the capacity will change.min
- the new minimum capacity to set.public void getChars(int start, int end, char[] dest, int destStart)
char[]
passed
starting at destStart
.start
- the inclusive start index of the characters to copy.end
- the exclusive end index of the characters to copy.dest
- the char[]
to copy the characters to.destStart
- the inclusive start index of dest
to begin copying to.IndexOutOfBoundsException
- if the start
is negative, the destStart
is
negative, the start
is greater than end
, the
end
is greater than the current length()
or
destStart + end - begin
is greater than
dest.length
.public int length()
public void setCharAt(int index, char ch)
index
.index
- the zero-based index of the character to replace.ch
- the character to set.IndexOutOfBoundsException
- if index
is negative or greater than or equal to the
current length()
.public void setLength(int length)
char
value of