Top Description Fields Constructors Methods
java.lang

pack-priv abstract sealed Class AbstractStringBuilder

extends Object
implements Appendable, CharSequence
permits StringBuilder, StringBuffer
Class Inheritance
All Implemented Interfaces
java.lang.CharSequence, java.lang.Appendable
Known Direct Subclasses
java.lang.StringBuilder, java.lang.StringBuffer
Imports
jdk.internal.math.DoubleToDecimal, .FloatToDecimal, java.io.IOException, java.nio.CharBuffer, java.util.Arrays, .Spliterator, java.util.stream.IntStream, .StreamSupport, jdk.internal.util.ArraysSupport, .Preconditions

A mutable sequence of characters.

Implements a modifiable string. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

Authors
Michael McCloskey, Martin Buchholz, Ulf Zibis
Since
1.5

Field Summary

Modifier and TypeField and Description
pack-priv byte
coder

The id of the encoding used to encode the bytes in value.

pack-priv int
count

The count is the number of characters used.

private static final byte[]
pack-priv boolean
maybeLatin1

The attribute indicates value might be compressible to LATIN1 if it is UTF16-encoded.

pack-priv byte[]
value

The value is used for character storage.

Constructor Summary

AccessConstructor and Description
pack-priv
AbstractStringBuilder()

This no-arg constructor is necessary for serialization of subclasses.

pack-priv
AbstractStringBuilder(int capacity)

Creates an AbstractStringBuilder of the specified capacity.

pack-priv
AbstractStringBuilder(String
the string to copy.
str
)

Constructs an AbstractStringBuilder that contains the same characters as the specified String.

pack-priv
AbstractStringBuilder(CharSequence
the sequence to copy.
seq
)

Constructs an AbstractStringBuilder that contains the same characters as the specified CharSequence.

Method Summary

Modifier and TypeMethod and Description
public AbstractStringBuilder

Returns:

a reference to this object.
append
(Object
an Object.
obj
)

Appends the string representation of the Object argument.

public AbstractStringBuilder

Returns:

a reference to this object.
append
(String
a string.
str
)

Appends the specified string to this character sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
append
(StringBuffer
the StringBuffer to append.
sb
)

Appends the specified StringBuffer to this sequence.

pack-priv AbstractStringBuilder
public AbstractStringBuilder
append(CharSequence
The character sequence to append. If csq is null, then the four characters "null" are appended to this Appendable.
s
)

Implements java.lang.Appendable.append.

Appends the specified character sequence to this Appendable.
public AbstractStringBuilder

Returns:

a reference to this object.
append
(CharSequence
the sequence to append.
s
,
int
the starting index of the subsequence to be appended.
start
,
int
the end index of the subsequence to be appended.
end
)

Implements java.lang.Appendable.append.

Appends a subsequence of the specified CharSequence to this sequence.
public AbstractStringBuilder

Returns:

a reference to this object.
append
(char[]
the characters to be appended.
str
)

Appends the string representation of the char array argument to this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
append
(char[]
the characters to be appended.
str
,
int
the index of the first char to append.
offset
,
int
the number of chars to append.
len
)

Appends the string representation of a subarray of the char array argument to this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
append
(boolean
a boolean.
b
)

Appends the string representation of the boolean argument to the sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
append
(char
a char.
c
)

Implements java.lang.Appendable.append.

Appends the string representation of the char argument to this sequence.
public AbstractStringBuilder

Returns:

a reference to this object.
append
(int
an int.
i
)

Appends the string representation of the int argument to this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
append
(long
a long.
l
)

Appends the string representation of the long argument to this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
append
(float
a float.
f
)

Appends the string representation of the float argument to this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
append
(double
a double.
d
)

Appends the string representation of the double argument to this sequence.

private final void
appendChars(char[] s, int off, int end)

private final void
appendChars(String s, int off, int end)

private final void
appendChars(CharSequence s, int off, int end)

public AbstractStringBuilder

Returns:

a reference to this object.
appendCodePoint
(int
a Unicode code point
codePoint
)

Appends the string representation of the codePoint argument to this sequence.

private AbstractStringBuilder
public int

Returns:

the current capacity
capacity
()

Returns the current capacity.

public char

Returns:

the char value at the specified index.
charAt
(int
the index of the desired char value.
index
)

Implements java.lang.CharSequence.charAt.

Returns the char value in this sequence at the specified index.
public IntStream
chars()

Overrides default java.lang.CharSequence.chars.

Returns a stream of int zero-extending the char values from this sequence.
public int

Returns:

the code point value of the character at the index
codePointAt
(int
the index to the char values
index
)

Returns the character (Unicode code point) at the specified index.

public int

Returns:

the Unicode code point value before the given index.
codePointBefore
(int
the index following the code point that should be returned
index
)

Returns the character (Unicode code point) before the specified index.

public int

Returns:

the number of Unicode code points in the specified text range
codePointCount
(int
the index to the first char of the text range.
beginIndex
,
int
the index after the last char of the text range.
endIndex
)

Returns the number of Unicode code points in the specified text range of this sequence.

public IntStream
codePoints()

Overrides default java.lang.CharSequence.codePoints.

Returns a stream of code point values from this sequence.
pack-priv int
compareTo(AbstractStringBuilder another)

Compares the objects of two AbstractStringBuilder implementations lexicographically.

public AbstractStringBuilder

Returns:

This object.
delete
(int
The beginning index, inclusive.
start
,
int
The ending index, exclusive.
end
)

Removes the characters in a substring of this sequence.

public AbstractStringBuilder

Returns:

This object.
deleteCharAt
(int
Index of char to remove
index
)

Removes the char at the specified position in this sequence.

public void
ensureCapacity(int
the minimum desired capacity.
minimumCapacity
)

Ensures that the capacity is at least equal to the specified minimum.

private void
ensureCapacityInternal(int minimumCapacity)

For positive values of minimumCapacity, this method behaves like ensureCapacity, however it is never synchronized.

pack-priv void
getBytes(byte[] dst, int dstBegin, byte coder)

public void
getChars(int
start copying at this offset.
srcBegin
,
int
stop copying at this offset.
srcEnd
,
char[]
the array to copy the data into.
dst
,
int
offset into dst.
dstBegin
)

Characters are copied from this sequence into the destination character array dst.

pack-priv final byte
pack-priv final byte[]
getValue()

Needed by String for the contentEquals method.

public int

Returns:

the index of the first occurrence of the specified substring, or -1 if there is no such occurrence.
indexOf
(String
the substring to search for.
str
)

Returns the index within this string of the first occurrence of the specified substring.

public int

Returns:

the index of the first occurrence of the specified substring, starting at the specified index, or -1 if there is no such occurrence.
indexOf
(String
the substring to search for.
str
,
int
the index from which to start the search.
fromIndex
)

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

private void
inflate()

If the coder is "isLatin1", this inflates the internal 8-bit storage to 16-bit <hi=0, low> pair storage.

private void
private void
pack-priv void
initBytes(char[] value, int off, int len)

public AbstractStringBuilder

Returns:

This object
insert
(int
position at which to insert subarray.
index
,
char[]
A char array.
str
,
int
the index of the first char in subarray to be inserted.
offset
,
int
the number of chars in the subarray to be inserted.
len
)

Inserts the string representation of a subarray of the str array argument into this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset.
offset
,
Object
an Object.
obj
)

Inserts the string representation of the Object argument into this character sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset.
offset
,
String
a string.
str
)

Inserts the string into this character sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset.
offset
,
char[]
a character array.
str
)

Inserts the string representation of the char array argument into this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset.
dstOffset
,
CharSequence
the sequence to be inserted
s
)

Inserts the specified CharSequence into this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset in this sequence.
dstOffset
,
CharSequence
the sequence to be inserted.
s
,
int
the starting index of the subsequence to be inserted.
start
,
int
the end index of the subsequence to be inserted.
end
)

Inserts a subsequence of the specified CharSequence into this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset.
offset
,
boolean
a boolean.
b
)

Inserts the string representation of the boolean argument into this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset.
offset
,
char
a char.
c
)

Inserts the string representation of the char argument into this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset.
offset
,
int
an int.
i
)

Inserts the string representation of the second int argument into this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset.
offset
,
long
a long.
l
)

Inserts the string representation of the long argument into this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset.
offset
,
float
a float.
f
)

Inserts the string representation of the float argument into this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
insert
(int
the offset.
offset
,
double
a double.
d
)

Inserts the string representation of the double argument into this sequence.

pack-priv final boolean
public int

Returns:

the index of the last occurrence of the specified substring, or -1 if there is no such occurrence.
lastIndexOf
(String
the substring to search for.
str
)

Returns the index within this string of the last occurrence of the specified substring.

public int

Returns:

the index of the last occurrence of the specified substring, searching backward from the specified index, or -1 if there is no such occurrence.
lastIndexOf
(String
the substring to search for.
str
,
int
the index to start the search from.
fromIndex
)

Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.

public int

Returns:

the length of the sequence of characters currently represented by this object
length
()

Implements java.lang.CharSequence.length.

Returns the length (character count).
pack-priv long

Returns:

updated accumulation of length and coder
mix
(long
running accumulation of length and coder
lengthCoder
)

Used by StringConcatHelper via JLA.

private int
newCapacity(int
the desired minimum capacity
minCapacity
)

Returns a capacity at least as large as the given minimum capacity.

public int

Returns:

the index within this sequence
offsetByCodePoints
(int
the index to be offset
index
,
int
the offset in code points
codePointOffset
)

Returns the index within this sequence that is offset from the given index by codePointOffset code points.

pack-priv long

Returns:

running accumulation of length and coder minus the number of characters added
prepend
(long
running accumulation of length and coder
lengthCoder
,
byte[]
concatenation buffer
buffer
)

Used by StringConcatHelper via JLA.

private final void
putCharsAt(int index, char[] s, int off, int end)

private final void
putCharsAt(int index, CharSequence s, int off, int end)

private void
putStringAt(int index, String str, int off, int end)

private void
putStringAt(int index, String str)

private AbstractStringBuilder
repeat(char c, int count)

public AbstractStringBuilder

Returns:

a reference to this object.
repeat
(int
code point to append
codePoint
,
int
number of times to copy
count
)

Repeats count copies of the string representation of the codePoint argument to this sequence.

public AbstractStringBuilder

Returns:

a reference to this object.
repeat
(CharSequence
a CharSequence
cs
,
int
number of times to copy
count
)

Appends count copies of the specified CharSequence cs to this sequence.

public AbstractStringBuilder

Returns:

This object.
replace
(int
The beginning index, inclusive.
start
,
int
The ending index, exclusive.
end
,
String
String that will replace previous contents.
str
)

Replaces the characters in a substring of this sequence with characters in the specified String.

public AbstractStringBuilder

Returns:

a reference to this object.
reverse
()

Causes this character sequence to be replaced by the reverse of the sequence.

public void
setCharAt(int
the index of the character to modify.
index
,
char
the new character.
ch
)

The character at the specified index is set to ch.

public void
setLength(int
the new length
newLength
)

Sets the length of the character sequence.

private void
shift(int offset, int n)

public CharSequence

Returns:

the specified subsequence.
subSequence
(int
the start index, inclusive.
start
,
int
the end index, exclusive.
end
)

Implements java.lang.CharSequence.subSequence.

Returns a new character sequence that is a subsequence of this sequence.
public String

Returns:

The new string.
substring
(int
The beginning index, inclusive.
start
)

Returns a new String that contains a subsequence of characters currently contained in this character sequence.

public String

Returns:

The new string.
substring
(int
The beginning index, inclusive.
start
,
int
The ending index, exclusive.
end
)

Returns a new String that contains a subsequence of characters currently contained in this sequence.

public abstract String

Returns:

a string representation of this sequence of characters.
toString
()

Redeclares java.lang.CharSequence.toString.

Overrides java.lang.Object.toString.

Returns a string representing the data in this sequence.
public void
trimToSize()

Attempts to reduce storage used for the character sequence.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait