APIdia Launch Partner
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.StringBuffer, java.lang.StringBuilder
Imports
jdk.internal.math.DoubleToDecimal, .FloatToDecimal, jdk.internal.util.DecimalDigits, .ArraysSupport, .Preconditions, java.nio.CharBuffer, java.util.Arrays, .Spliterator, java.util.stream.IntStream, .StreamSupport

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 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 static byte[]

Returns:

buffer with new characters appended, possibly inflated
appendChars
(byte[]
the current buffer
value
,
byte
the coder of the buffer
coder
,
int
the character count
count
,
char[]
a char array
s
,
int
the offset of the first character to append
off
,
int
end last (exclusive) character to append
end
)

Returns buffer with new characters appended, possibly inflated.

private static byte[]

Returns:

buffer with new characters appended, possibly inflated
appendChars
(byte[]
the current buffer
value
,
byte
the coder of the buffer
coder
,
int
the character count
count
,
String
a string
s
,
int
the offset of the first character to append
off
,
int
end last (exclusive) character to append
end
)

Returns buffer with new characters appended, possibly inflated.

private static byte[]

Returns:

buffer with new characters appended, possibly inflated
appendChars
(byte[]
the current buffer
value
,
byte
the coder of the buffer
coder
,
int
the character count
count
,
CharSequence
CharSequence to append characters from
s
,
int
the offset of the first character to append
off
,
int
end last (exclusive) character to append
end
)

Returns buffer with new characters appended, possibly inflated.

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 static byte[]

Returns:

the value, with the requested coder, in a buffer with at least the minimum capacity
ensureCapacityNewCoder
(byte[]
the current buffer
value
,
byte
of the current buffer
coder
,
int
the count of chars in the current buffer
count
,
int
the new minimum capacity
minimumCapacity
,
byte
the desired new coder
newCoder
)

Returns the value, with the requested coder, in a buffer with at least the minimum capacity.

private static byte[]

Returns:

the value buffer sufficient to hold the minimumCapactity and a copy of the contents
ensureCapacitySameCoder
(byte[]
the current buffer
value
,
byte
of the current buffer
coder
,
int
the new minimum capacity
minimumCapacity
)

Returns the value buffer sufficient to hold the minimumCapactity and a copy of the contents.

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

public void
getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)

Overrides default java.lang.CharSequence.getChars.

Copies characters from this sequence into the given destination array.

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 static byte[]
inflateIfNeededFor(byte[] value, int count, byte coder, byte otherCoder)

private static byte[]

Returns:

the new buffer, the caller is responsible for updates to the coder
inflateToUTF16
(byte[]
the current byte array buffer
value
,
int
the number of latin1 characters to convert to UTF16
count
)

Inflates the internal 8-bit latin1 storage to 16-bit <hi=0, low> pair storage.

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
private static boolean
isLatin1(byte coder)

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).

private static boolean

Returns:

true if the byte array should be replaced due to increased capacity or coder change
needsNewBuffer
(byte[]
a byte array
value
,
byte
old coder
coder
,
int
new capacity in characters
newCapacity
,
byte
new coder
newCoder
)

Returns true if the byte array should be replaced due to increased capacity or coder change.

private static int
newCapacity(byte[]
the current buffer
value
,
byte
of the current buffer
coder
,
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.

private static byte[]

Returns:

Return the buffer containing the composed string and inserted characters
putCharsAt
(byte[]
byte array destination for the string (if the coder matches)
value
,
byte
the original buffer coder
coder
,
int
the count of characters in the original buffer
count
,
int
the insertion point
index
,
char[]
char[] array to insert from
s
,
int
offset of the first character
off
,
int
the offset of the last character (exclusive)
end
)

Returns Return the buffer containing the composed string and inserted characters.

private static byte[]

Returns:

Return the buffer containing the composed string and inserted characters
putCharsAt
(byte[]
byte array destination for the string (if the coder matches)
value
,
byte
the original buffer coder
coder
,
int
the count of characters in the original buffer
count
,
int
the insertion point
index
,
CharSequence
CharSequence to insert from
s
,
int
offset of the first character
off
,
int
the offset of the last character (exclusive)
end
)

Returns Return the buffer containing the composed string and inserted characters.

private static byte[]

Returns:

the buffer with the substring inserted
putStringAt
(byte[]
an existing buffer to insert into
value
,
byte
the coder of the buffer
coder
,
int
the count of characters in the buffer
count
,
int
the index to insert the string
index
,
String
the string
str
)

Returns the buffer with the substring inserted.

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 static void
shift(byte[] value, byte coder, int count, 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 character sequence that is a subsequence of this sequence.

public String

Returns:

A string containing the specified subsequence of characters.
substring
(int
The beginning index, inclusive.
start
)

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

public String

Returns:

A string containing the specified subsequence of characters.
substring
(int
The beginning index, inclusive.
start
,
int
The ending index, exclusive.
end
)

Returns a 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