DthingApi
Public Member Functions | List of all members
java.lang.StringBuilder Class Reference

Public Member Functions

 StringBuilder ()
 
 StringBuilder (int capacity)
 
 StringBuilder (String str)
 
StringBuilder append (boolean b)
 
StringBuilder append (char c)
 
StringBuilder append (int i)
 
StringBuilder append (long l)
 
StringBuilder append (float f)
 
StringBuilder append (double d)
 
StringBuilder append (Object obj)
 
StringBuilder append (String str)
 
StringBuilder append (StringBuffer sb)
 
StringBuilder append (char[] chars)
 
StringBuilder append (char[] str, int offset, int len)
 
StringBuilder delete (int start, int end)
 
StringBuilder deleteCharAt (int index)
 
StringBuilder insert (int offset, boolean b)
 
StringBuilder insert (int offset, char c)
 
StringBuilder insert (int offset, int i)
 
StringBuilder insert (int offset, long l)
 
StringBuilder insert (int offset, float f)
 
StringBuilder insert (int offset, double d)
 
StringBuilder insert (int offset, Object obj)
 
StringBuilder insert (int offset, String str)
 
StringBuilder insert (int offset, char[] ch)
 
StringBuilder insert (int offset, char[] str, int strOffset, int strLen)
 
StringBuilder replace (int start, int end, String str)
 
StringBuilder reverse ()
 
String toString ()
 
int length ()
 
CharSequence subSequence (int start, int end)
 

Detailed Description

A modifiable sequence of characters for use in creating strings. This class is intended as a direct replacement of StringBuffer for non-concurrent use; unlike

StringBuffer

this class is not synchronized.

For particularly complex string-building needs, consider java.util.Formatter.

The majority of the modification methods on this class return

this

so that method calls can be chained together. For example:

new StringBuilder("a").append("b").append("c").toString()

.

See also
CharSequence
Appendable
StringBuffer
String
String::format
Since
1.5

Constructor & Destructor Documentation

◆ StringBuilder() [1/3]

java.lang.StringBuilder.StringBuilder ( )
inline

Constructs an instance with an initial capacity of

16

.

See also
#capacity()

◆ StringBuilder() [2/3]

java.lang.StringBuilder.StringBuilder ( int  capacity)
inline

Constructs an instance with the specified capacity.

Parameters
capacitythe initial capacity to use.
Exceptions
NegativeArraySizeExceptionif the specified
capacity
is negative.
See also
#capacity()

◆ StringBuilder() [3/3]

java.lang.StringBuilder.StringBuilder ( String  str)
inline

Constructs an instance that's initialized with the contents of the specified

String

. The capacity of the new builder will be the length of the

String

plus 16.

Parameters
strthe
String
to copy into the builder.
Exceptions
NullPointerExceptionif
str
is
null
.

Member Function Documentation

◆ append() [1/11]

StringBuilder java.lang.StringBuilder.append ( boolean  b)
inline

Appends the string representation of the specified

boolean

value. The

boolean

value is converted to a String according to the rule defined by String#valueOf(boolean).

Parameters
bthe
boolean
value to append.
Returns
this builder.
See also
String::valueOf(boolean)

◆ append() [2/11]

StringBuilder java.lang.StringBuilder.append ( char  c)
inline

Appends the string representation of the specified

char

value. The

char

value is converted to a string according to the rule defined by String#valueOf(char).

Parameters
cthe
char
value to append.
Returns
this builder.
See also
String::valueOf(char)

◆ append() [3/11]

StringBuilder java.lang.StringBuilder.append ( int  i)
inline

Appends the string representation of the specified

int

value. The

int

value is converted to a string according to the rule defined by String#valueOf(int).

Parameters
ithe
int
value to append.
Returns
this builder.
See also
String::valueOf(int)

◆ append() [4/11]

StringBuilder java.lang.StringBuilder.append ( long  l)
inline

Appends the string representation of the specified

long

value. The

long

value is converted to a string according to the rule defined by String#valueOf(long).

Parameters
lthe
long
value.
Returns
this builder.
See also
String::valueOf(long)

◆ append() [5/11]

StringBuilder java.lang.StringBuilder.append ( float  f)
inline

Appends the string representation of the specified

float

value. The

float

value is converted to a string according to the rule defined by String#valueOf(float).

Parameters
fthe
float
value to append.
Returns
this builder.
See also
String::valueOf(float)

◆ append() [6/11]

StringBuilder java.lang.StringBuilder.append ( double  d)
inline

Appends the string representation of the specified

double

value. The

double

value is converted to a string according to the rule defined by String#valueOf(double).

Parameters
dthe
double
value to append.
Returns
this builder.
See also
String::valueOf(double)

◆ append() [7/11]

StringBuilder java.lang.StringBuilder.append ( Object  obj)
inline

Appends the string representation of the specified

Object

. The

Object

value is converted to a string according to the rule defined by String#valueOf(Object).

Parameters
objthe
Object
to append.
Returns
this builder.
See also
String::valueOf(Object)

◆ append() [8/11]

StringBuilder java.lang.StringBuilder.append ( String  str)
inline

Appends the contents of the specified string. If the string is

null

, then the string

"null"

is appended.

Parameters
strthe string to append.
Returns
this builder.

◆ append() [9/11]

StringBuilder java.lang.StringBuilder.append ( StringBuffer  sb)
inline

Appends the contents of the specified

StringBuffer

. If the StringBuffer is

null

, then the string

"null"

is appended.

Parameters
sbthe
StringBuffer
to append.
Returns
this builder.

◆ append() [10/11]

StringBuilder java.lang.StringBuilder.append ( char []  chars)
inline

Appends the string representation of the specified

char[]

. The

char[]

is converted to a string according to the rule defined by String#valueOf(char[]).

Parameters
charsthe
char[]
to append..
Returns
this builder.
See also
String::valueOf(char[])

◆ append() [11/11]

StringBuilder java.lang.StringBuilder.append ( char []  str,
int  offset,
int  len 
)
inline

Appends the string representation of the specified subset of the

char[]

. The

char[]

value is converted to a String according to the rule defined by String#valueOf(char[],int,int).

Parameters
strthe
char[]
to append.
offsetthe inclusive offset index.
lenthe number of characters.
Returns
this builder.
Exceptions
ArrayIndexOutOfBoundsExceptionif
offset
and
len
do not specify a valid subsequence.
See also
String::valueOf(char[],int,int)

◆ delete()

StringBuilder java.lang.StringBuilder.delete ( int  start,
int  end 
)
inline

Deletes a sequence of characters specified by

start

and

end

. Shifts any remaining characters to the left.

Parameters
startthe inclusive start index.
endthe exclusive end index.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
start
is less than zero, greater than the current length or greater than
end
.

◆ deleteCharAt()

StringBuilder java.lang.StringBuilder.deleteCharAt ( int  index)
inline

Deletes the character at the specified index. shifts any remaining characters to the left.

Parameters
indexthe index of the character to delete.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
index
is less than zero or is greater than or equal to the current length.

◆ insert() [1/10]

StringBuilder java.lang.StringBuilder.insert ( int  offset,
boolean  b 
)
inline

Inserts the string representation of the specified

boolean

value at the specified

offset

. The

boolean

value is converted to a string according to the rule defined by String#valueOf(boolean).

Parameters
offsetthe index to insert at.
bthe
boolean
value to insert.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
offset
is negative or greater than the current
length
.
See also
String::valueOf(boolean)

◆ insert() [2/10]

StringBuilder java.lang.StringBuilder.insert ( int  offset,
char  c 
)
inline

Inserts the string representation of the specified

char

value at the specified

offset

. The

char

value is converted to a string according to the rule defined by String#valueOf(char).

Parameters
offsetthe index to insert at.
cthe
char
value to insert.
Returns
this builder.
Exceptions
IndexOutOfBoundsExceptionif
offset
is negative or greater than the current
length()
.
See also
String::valueOf(char)

◆ insert() [3/10]

StringBuilder java.lang.StringBuilder.insert ( int  offset,
int  i 
)
inline

Inserts the string representation of the specified

int

value at the specified

offset

. The

int

value is converted to a String according to the rule defined by String#valueOf(int).

Parameters
offsetthe index to insert at.
ithe
int
value to insert.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
offset
is negative or greater than the current
length()
.
See also
String::valueOf(int)

◆ insert() [4/10]

StringBuilder java.lang.StringBuilder.insert ( int  offset,
long  l 
)
inline

Inserts the string representation of the specified

long

value at the specified

offset

. The

long

value is converted to a String according to the rule defined by String#valueOf(long).

Parameters
offsetthe index to insert at.
lthe
long
value to insert.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
offset
is negative or greater than the current {code length()}.
See also
String::valueOf(long)

◆ insert() [5/10]

StringBuilder java.lang.StringBuilder.insert ( int  offset,
float  f 
)
inline

Inserts the string representation of the specified

float

value at the specified

offset

. The

float

value is converted to a string according to the rule defined by String#valueOf(float).

Parameters
offsetthe index to insert at.
fthe
float
value to insert.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
offset
is negative or greater than the current
length()
.
See also
String::valueOf(float)

◆ insert() [6/10]

StringBuilder java.lang.StringBuilder.insert ( int  offset,
double  d 
)
inline

Inserts the string representation of the specified

double

value at the specified

offset

. The

double

value is converted to a String according to the rule defined by String#valueOf(double).

Parameters
offsetthe index to insert at.
dthe
double
value to insert.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
offset
is negative or greater than the current
length()
.
See also
String::valueOf(double)

◆ insert() [7/10]

StringBuilder java.lang.StringBuilder.insert ( int  offset,
Object  obj 
)
inline

Inserts the string representation of the specified

Object

at the specified

offset

. The

Object

value is converted to a String according to the rule defined by String#valueOf(Object).

Parameters
offsetthe index to insert at.
objthe
Object
to insert.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
offset
is negative or greater than the current
length()
.
See also
String::valueOf(Object)

◆ insert() [8/10]

StringBuilder java.lang.StringBuilder.insert ( int  offset,
String  str 
)
inline

Inserts the specified string at the specified

offset

. If the specified string is null, then the String

"null"

is inserted.

Parameters
offsetthe index to insert at.
strthe
String
to insert.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
offset
is negative or greater than the current
length()
.

◆ insert() [9/10]

StringBuilder java.lang.StringBuilder.insert ( int  offset,
char []  ch 
)
inline

Inserts the string representation of the specified

char[]

at the specified

offset

. The

char[]

value is converted to a String according to the rule defined by String#valueOf(char[]).

Parameters
offsetthe index to insert at.
chthe
char[]
to insert.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
offset
is negative or greater than the current
length()
.
See also
String::valueOf(char[])

◆ insert() [10/10]

StringBuilder java.lang.StringBuilder.insert ( int  offset,
char []  str,
int  strOffset,
int  strLen 
)
inline

Inserts the string representation of the specified subsequence of the

char[]

at the specified

offset

. The

char[]

value is converted to a String according to the rule defined by String#valueOf(char[],int,int).

Parameters
offsetthe index to insert at.
strthe
char[]
to insert.
strOffsetthe inclusive index.
strLenthe number of characters.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
offset
is negative or greater than the current
length()
, or
strOffset
and
strLen
do not specify a valid subsequence.
See also
String::valueOf(char[],int,int)

◆ replace()

StringBuilder java.lang.StringBuilder.replace ( int  start,
int  end,
String  str 
)
inline

Replaces the specified subsequence in this builder with the specified string.

Parameters
startthe inclusive begin index.
endthe exclusive end index.
strthe replacement string.
Returns
this builder.
Exceptions
StringIndexOutOfBoundsExceptionif
start
is negative, greater than the current
length()
or greater than
end
.
NullPointerExceptionif
str
is
null
.

◆ reverse()

StringBuilder java.lang.StringBuilder.reverse ( )
inline

Reverses the order of characters in this builder.

Returns
this buffer.

◆ toString()

String java.lang.StringBuilder.toString ( )
inline

Returns the contents of this builder.

Returns
the string representation of the data in this builder.

The documentation for this class was generated from the following file: