Top Description Inners Fields Constructors Methods
org.apache.commons.text

public Class TextStringBuilder

extends Object
implements CharSequence, Appendable, Serializable, Builder<String>
Class Inheritance
All Implemented Interfaces
org.apache.commons.text.Builder, java.util.function.Supplier, java.io.Serializable, java.lang.Appendable, java.lang.CharSequence
Imports
java.io.IOException, .Reader, .Serializable, .Writer, java.nio.CharBuffer, java.util.Arrays, .Iterator, .List, .Objects, org.apache.commons.lang3.ArrayUtils, .StringUtils, org.apache.commons.text.matcher.StringMatcher

References Deprecated

Builder is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Builds a string from constituent parts providing a more flexible and powerful API than StringBuffer and StringBuilder.

The main differences from StringBuffer/StringBuilder are:

The aim has been to provide an API that mimics very closely what StringBuffer provides, but with additional methods. It should be noted that some edge cases, with invalid indices or null input, have been altered - see individual methods. The biggest of these changes is that by default, null will not output the text 'null'. This can be controlled by a property, setNullText(String).

This class is called TextStringBuilder instead of StringBuilder to avoid clashing with StringBuilder.

Since
1.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
TextStringBuilder.TextStringBuilderReader

Inner class to allow StrBuilder to operate as a reader.

pack-priv class
TextStringBuilder.TextStringBuilderTokenizer

Inner class to allow StrBuilder to operate as a tokenizer.

pack-priv class
TextStringBuilder.TextStringBuilderWriter

Inner class to allow StrBuilder to operate as a writer.

Field Summary

Modifier and TypeField and Description
private char[]
buffer

Internal data storage.

pack-priv static final int
CAPACITY

The extra capacity for new builders.

private static final int
EOS

End-Of-Stream.

private static final int
FALSE_STRING_SIZE

The size of the string "false".

private static final int
MAX_BUFFER_SIZE

The maximum size buffer to allocate.

private String
newLine

The new line, null means use the system default from System#lineSeparator().

private String
nullText

The null text.

private int
reallocations

Incremented when the buffer is reallocated.

private static final long
serialVersionUID

Required for serialization support.

private int
size

Current size of the buffer.

private static final char
SPACE

The space character.

private static final int
TRUE_STRING_SIZE

The size of the string "true".

Constructor Summary

AccessConstructor and Description
public
TextStringBuilder()

Constructs an empty builder with an initial capacity of 32 characters.

private
TextStringBuilder(final char[]
a reference to a character array, must not be null.
initialBuffer
,
final int
The length of the subarray to be used; must be non-negative and no larger than initialBuffer.length. The new builder's size will be set to length.
length
)

Constructs an instance from a reference to a character array.

public
TextStringBuilder(final CharSequence
the string to copy, null treated as blank string.
seq
)

Constructs an instance from a character sequence, allocating 32 extra characters for growth.

public
TextStringBuilder(final int
the initial capacity, zero or less will be converted to 32.
initialCapacity
)

Constructs an instance with the specified initial capacity.

public
TextStringBuilder(final String
the string to copy, null treated as blank string.
str
)

Constructs an instance from a string, allocating 32 extra characters for growth.

Method Summary

Modifier and TypeMethod and Description
public TextStringBuilder

Returns:

this instance.
append
(final boolean
the value to append.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a boolean value to the string builder.

public TextStringBuilder

Returns:

this instance.
append
(final char
the value to append.
ch
)

Implements java.lang.Appendable.append.

References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a char value to the string builder.

public TextStringBuilder

Returns:

this instance.
append
(final char[]
the char array to append.
chars
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a char array to the string builder.

public TextStringBuilder

Returns:

this instance.
append
(final char[]
the char array to append.
chars
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a char array to the string builder.

public TextStringBuilder

Returns:

this instance.
append
(final CharBuffer
the char buffer to append.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends the contents of a char buffer to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final CharBuffer
the char buffer to append.
buf
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends the contents of a char buffer to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final CharSequence
the CharSequence to append.
seq
)

Implements java.lang.Appendable.append.

References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a CharSequence to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final CharSequence
the CharSequence to append.
seq
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the end index, exclusive, must be valid.
endIndex
)

Implements java.lang.Appendable.append.

References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends part of a CharSequence to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final double
the value to append.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a double value to the string builder using String.valueOf.

public TextStringBuilder

Returns:

this instance.
append
(final float
the value to append.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a float value to the string builder using String.valueOf.

public TextStringBuilder

Returns:

this instance.
append
(final int
the value to append.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an int value to the string builder using String.valueOf.

public TextStringBuilder

Returns:

this instance.
append
(final long
the value to append.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a long value to the string builder using String.valueOf.

public TextStringBuilder

Returns:

this instance.
append
(final Object
the object to append.
obj
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an object to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final String
the string to append.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a string to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final String
the string to append.
str
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends part of a string to this string builder.

public TextStringBuilder

Returns:

this to enable chaining.
append
(final String
the format string.
format
,
final Object...
the objects to use in the format string.
objs
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Calls String#format(String, Object...) and appends the result.

public TextStringBuilder

Returns:

this instance.
append
(final StringBuffer
the string buffer to append.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a string buffer to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final StringBuffer
the string to append.
str
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends part of a string buffer to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final StringBuilder
the StringBuilder to append.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a StringBuilder to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final StringBuilder
the StringBuilder to append.
str
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends part of a StringBuilder to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final TextStringBuilder
the string builder to append.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends another string builder to this string builder.

public TextStringBuilder

Returns:

this instance.
append
(final TextStringBuilder
the string to append.
str
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends part of a string builder to this string builder.

public TextStringBuilder

Returns:

this instance.
appendAll
(final Iterable<?>
the iterable to append.
iterable
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends each item in an iterable to the builder without any separators.

public TextStringBuilder

Returns:

this instance.
appendAll
(final Iterator<?>
the iterator to append.
it
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends each item in an iterator to the builder without any separators.

public <
the element type.
T
>
TextStringBuilder

Returns:

this instance.
appendAll
(final T...
the array to append.
array
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends each item in an array to the builder without any separators.

private void
appendFalse(int index)

Appends "false".

public TextStringBuilder

Returns:

this instance.
appendFixedWidthPadLeft
(final int
the value to append.
value
,
final int
the fixed field width, zero or negative has no effect.
width
,
final char
the pad character to use.
padChar
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an object to the builder padding on the left to a fixed width.

public TextStringBuilder

Returns:

this instance.
appendFixedWidthPadLeft
(final Object
the object to append, null uses null text.
obj
,
final int
the fixed field width, zero or negative has no effect.
width
,
final char
the pad character to use.
padChar
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an object to the builder padding on the left to a fixed width.

public TextStringBuilder

Returns:

this instance.
appendFixedWidthPadRight
(final int
the value to append.
value
,
final int
the fixed field width, zero or negative has no effect.
width
,
final char
the pad character to use.
padChar
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an object to the builder padding on the right to a fixed length.

public TextStringBuilder

Returns:

this instance.
appendFixedWidthPadRight
(final Object
the object to append, null uses null text.
obj
,
final int
the fixed field width, zero or negative has no effect.
width
,
final char
the pad character to use.
padChar
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an object to the builder padding on the right to a fixed length.

public TextStringBuilder

Returns:

this instance.
appendln
(final boolean
the value to append.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a boolean value followed by a new line to the string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final char
the value to append.
ch
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a char value followed by a new line to the string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final char[]
the char array to append.
chars
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a char array followed by a new line to the string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final char[]
the char array to append.
chars
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a char array followed by a new line to the string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final double
the value to append.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a double value followed by a new line to the string builder using String.valueOf.

public TextStringBuilder

Returns:

this instance.
appendln
(final float
the value to append.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a float value followed by a new line to the string builder using String.valueOf.

public TextStringBuilder

Returns:

this instance.
appendln
(final int
the value to append.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an int value followed by a new line to the string builder using String.valueOf.

public TextStringBuilder

Returns:

this instance.
appendln
(final long
the value to append.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a long value followed by a new line to the string builder using String.valueOf.

public TextStringBuilder

Returns:

this instance.
appendln
(final Object
the object to append.
obj
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an object followed by a new line to this string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final String
the string to append.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a string followed by a new line to this string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final String
the string to append.
str
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends part of a string followed by a new line to this string builder.

public TextStringBuilder

Returns:

this to enable chaining.
appendln
(final String
the format string.
format
,
final Object...
the objects to use in the format string.
objs
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Calls String#format(String, Object...) and appends the result.

public TextStringBuilder

Returns:

this instance.
appendln
(final StringBuffer
the string buffer to append.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a string buffer followed by a new line to this string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final StringBuffer
the string to append.
str
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends part of a string buffer followed by a new line to this string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final StringBuilder
the string builder to append.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a string builder followed by a new line to this string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final StringBuilder
the string builder to append.
str
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends part of a string builder followed by a new line to this string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final TextStringBuilder
the string builder to append.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends another string builder followed by a new line to this string builder.

public TextStringBuilder

Returns:

this instance.
appendln
(final TextStringBuilder
the string to append.
str
,
final int
the start index, inclusive, must be valid.
startIndex
,
final int
the length to append, must be valid.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends part of a string builder followed by a new line to this string builder.

public TextStringBuilder

Returns:

this instance.
appendNewLine
()
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends this builder's new line string to this builder.

public TextStringBuilder

Returns:

this instance.
appendNull
()
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends the text representing null to this string builder.

public TextStringBuilder

Returns:

this instance.
appendPadding
(final int
the length to append, negative means no append.
length
,
final char
the character to append.
padChar
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends the pad character to the builder the specified number of times.

public TextStringBuilder

Returns:

this instance.
appendSeparator
(final char
the separator to use.
separator
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a separator if the builder is currently non-empty.

public TextStringBuilder

Returns:

this instance.
appendSeparator
(final char
the separator if builder is not empty.
standard
,
final char
the separator if builder is empty.
defaultIfEmpty
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends one of both separators to the builder If the builder is currently empty it will append the defaultIfEmpty-separator Otherwise it will append the standard-separator

The separator is appended using append(char).

public TextStringBuilder

Returns:

this instance.
appendSeparator
(final char
the separator to use.
separator
,
final int
the loop index.
loopIndex
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a separator to the builder if the loop index is greater than zero.

public TextStringBuilder

Returns:

this instance.
appendSeparator
(final String
the separator to use, null means no separator.
separator
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a separator if the builder is currently non-empty.

public TextStringBuilder

Returns:

this instance.
appendSeparator
(final String
the separator to use, null means no separator.
separator
,
final int
the loop index.
loopIndex
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends a separator to the builder if the loop index is greater than zero.

public TextStringBuilder

Returns:

this instance.
appendSeparator
(final String
the separator if builder is not empty, null means no separator.
standard
,
final String
the separator if builder is empty, null means no separator.
defaultIfEmpty
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends one of both separators to the StrBuilder.

public void
appendTo(final Appendable
the appendable to append data to.
appendable
)

Appends current contents of this StrBuilder to the provided Appendable.

private void
appendTrue(int index)

Appends "true".

public TextStringBuilder

Returns:

this instance.
appendWithSeparators
(final Iterable<?>
the iterable to append.
iterable
,
final String
the separator to use, null means no separator.
separator
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an iterable placing separators between each value, but not before the first or after the last.

public TextStringBuilder

Returns:

this instance.
appendWithSeparators
(final Iterator<?>
the iterator to append.
it
,
final String
the separator to use, null means no separator.
separator
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an iterator placing separators between each value, but not before the first or after the last.

public TextStringBuilder

Returns:

this instance.
appendWithSeparators
(final Object[]
the array to append.
array
,
final String
the separator to use, null means no separator.
separator
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Appends an array placing separators between each value, but not before the first or after the last.

public Reader

Returns:

a reader that reads from this builder.
asReader
()

Gets the contents of this builder as a Reader.

public StringTokenizer

Returns:

a tokenizer that is linked to this builder.
asTokenizer
()

Creates a tokenizer that can tokenize the contents of this builder.

public Writer

Returns:

a writer that populates this builder.
asWriter
()

Gets this builder as a Writer that can be written to.

public String

Returns:

This instance as a String.
build
()

Implements org.apache.commons.text.Builder.build.

Deprecated Use get().

Converts this instance to a String.

public int

Returns:

The capacity.
capacity
()

Gets the current size of the internal character array buffer.

public char

Returns:

The character at the index.
charAt
(final int
the index to retrieve, must be valid.
index
)

Implements java.lang.CharSequence.charAt.

Gets the character at the specified index.

public TextStringBuilder

Returns:

this instance.
clear
()
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Clears the string builder (convenience Collections API style method).

public boolean

Returns:

true if the builder contains the character.
contains
(final char
the character to find.
ch
)

Tests if the string builder contains the specified char.

public boolean

Returns:

true if the builder contains the string.
contains
(final String
the string to find.
str
)

Tests if the string builder contains the specified string.

public boolean

Returns:

true if the matcher finds a match in the builder.
contains
(final StringMatcher
the matcher to use, null returns -1.
matcher
)

Tests if the string builder contains a string matched using the specified matcher.

private static int

Returns:

the capacity
createPositiveCapacity
(final int
the minimum capacity
minCapacity
)

Creates a positive capacity at least as large the minimum required capacity.

public TextStringBuilder

Returns:

this instance.
delete
(final int
the start index, inclusive, must be valid.
startIndex
,
final int
the end index, exclusive, must be valid except that if too large it is treated as end of string.
endIndex
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Deletes the characters between the two specified indices.

public TextStringBuilder

Returns:

this instance.
deleteAll
(final char
the character to delete.
ch
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Deletes the character wherever it occurs in the builder.

public TextStringBuilder

Returns:

this instance.
deleteAll
(final String
the string to delete, null causes no action.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Deletes the string wherever it occurs in the builder.

public TextStringBuilder

Returns:

this instance.
deleteAll
(final StringMatcher
the matcher to use to find the deletion, null causes no action.
matcher
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Deletes all parts of the builder that the matcher matches.

public TextStringBuilder

Returns:

this instance.
deleteCharAt
(final int
the index to delete.
index
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Deletes the character at the specified index.

public TextStringBuilder

Returns:

this instance.
deleteFirst
(final char
the character to delete.
ch
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Deletes the character wherever it occurs in the builder.

public TextStringBuilder

Returns:

this instance.
deleteFirst
(final String
the string to delete, null causes no action.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Deletes the string wherever it occurs in the builder.

public TextStringBuilder

Returns:

this instance.
deleteFirst
(final StringMatcher
the matcher to use to find the deletion, null causes no action.
matcher
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Deletes the first match within the builder using the specified matcher.

private void
deleteImpl(final int
the start index, must be valid.
startIndex
,
final int
the end index (exclusive), must be valid.
endIndex
,
final int
the length, must be valid.
len
)

Internal method to delete a range without validation.

public char

Returns:

The character at the index
drainChar
(final int
the index to retrieve, must be valid
index
)

Gets the character at the specified index before deleting it.

public int

Returns:

How many characters where copied (then deleted). If this builder is empty, return 0.
drainChars
(final int
first index to copy, inclusive.
startIndex
,
final int
last index to copy, exclusive.
endIndex
,
final char[]
the target array, must not be null.
target
,
final int
the index to start copying in the target.
targetIndex
)

Drains (copies, then deletes) this character sequence into the specified array.

public boolean

Returns:

true if the builder ends with the string.
endsWith
(final String
the string to search for, null returns false.
str
)

Checks whether this builder ends with the specified string.

public TextStringBuilder

Returns:

this instance.
ensureCapacity
(final int
the capacity to ensure.
capacity
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Tests the capacity and ensures that it is at least the size specified.

private void
ensureCapacityInternal(final int
the capacity to ensure.
capacity
)

Ensures that the buffer is at least the size specified.

public boolean

Returns:

true if the builders contain the same characters in the same order.
equals
(final Object
the object to check, null returns false.
obj
)

Overrides java.lang.Object.equals.

Tests the contents of this builder against another to see if they contain the same character content.

public boolean

Returns:

true if the builders contain the same characters in the same order.
equals
(final TextStringBuilder
the object to check, null returns false.
other
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Tests the contents of this builder against another to see if they contain the same character content.

public boolean

Returns:

true if the builders contain the same characters in the same order.
equalsIgnoreCase
(final TextStringBuilder
the object to check, null returns false.
other
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Tests the contents of this builder against another to see if they contain the same character content ignoring case.

public String

Returns:

This instance as a String.
get
()

Implements java.util.function.Supplier.get.

Converts this instance to a String.

pack-priv char[]
getBuffer()

Gets a direct reference to internal storage, not for public consumption.

public char[]

Returns:

The input array, unless that was null or too small.
getChars
(char[]
the target array, null will cause an array to be created.
target
)

Copies this character array into the specified array.

public void
getChars(final int
first index to copy, inclusive, must be valid.
startIndex
,
final int
last index to copy, exclusive, must be valid.
endIndex
,
final char[]
the target array, must not be null or too small.
target
,
final int
the index to start copying in target.
targetIndex
)

Overrides default java.lang.CharSequence.getChars.

Copies this character array into the specified array.

public String

Returns:

The new line text, null means use the system default from System#lineSeparator().
getNewLineText
()

Gets the text to be appended when a new line is added.

public String

Returns:

The null text, null means no append.
getNullText
()

Gets the text to be appended when null is added.

public int

Returns:

a hash code.
hashCode
()

Overrides java.lang.Object.hashCode.

Gets a suitable hash code for this builder.

public int

Returns:

The first index of the character, or -1 if not found.
indexOf
(final char
the character to find.
ch
)

Searches the string builder to find the first reference to the specified char.

public int

Returns:

The first index of the character, or -1 if not found.
indexOf
(final char
the character to find.
ch
,
int
the index to start at, invalid index rounded to edge.
startIndex
)

Searches the string builder to find the first reference to the specified char.

public int

Returns:

The first index of the string, or -1 if not found.
indexOf
(final String
the string to find, null returns -1.
str
)

Searches the string builder to find the first reference to the specified string.

public int

Returns:

The first index of the string, or -1 if not found.
indexOf
(final String
the string to find, null returns -1.
str
,
int
the index to start at, invalid index rounded to edge.
startIndex
)

Searches the string builder to find the first reference to the specified string starting searching from the given index.

public int

Returns:

The first index matched, or -1 if not found.
indexOf
(final StringMatcher
the matcher to use, null returns -1.
matcher
)

Searches the string builder using the matcher to find the first match.

public int

Returns:

The first index matched, or -1 if not found.
indexOf
(final StringMatcher
the matcher to use, null returns -1.
matcher
,
int
the index to start at, invalid index rounded to edge.
startIndex
)

Searches the string builder using the matcher to find the first match searching from the given index.

public TextStringBuilder

Returns:

this instance.
insert
(final int
the index to add at, must be valid.
index
,
final boolean
the value to insert.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Inserts the value into this builder.

public TextStringBuilder

Returns:

this instance.
insert
(final int
the index to add at, must be valid.
index
,
final char
the value to insert.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Inserts the value into this builder.

public TextStringBuilder

Returns:

this instance.
insert
(final int
the index to add at, must be valid.
index
,
final char[]
the char array to insert.
chars
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Inserts the character array into this builder.

public TextStringBuilder

Returns:

this instance.
insert
(final int
the index to add at, must be valid.
index
,
final char[]
the char array to insert.
chars
,
final int
the offset into the character array to start at, must be valid.
offset
,
final int
the length of the character array part to copy, must be positive.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Inserts part of the character array into this builder.

public TextStringBuilder

Returns:

this instance.
insert
(final int
the index to add at, must be valid.
index
,
final double
the value to insert.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Inserts the value into this builder.

public TextStringBuilder

Returns:

this instance.
insert
(final int
the index to add at, must be valid.
index
,
final float
the value to insert.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Inserts the value into this builder.

public TextStringBuilder

Returns:

this instance.
insert
(final int
the index to add at, must be valid.
index
,
final int
the value to insert.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Inserts the value into this builder.

public TextStringBuilder

Returns:

this instance.
insert
(final int
the index to add at, must be valid.
index
,
final long
the value to insert.
value
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Inserts the value into this builder.

public TextStringBuilder

Returns:

this instance.
insert
(final int
the index to add at, must be valid.
index
,
final Object
the object to insert.
obj
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Inserts the string representation of an object into this builder.

public TextStringBuilder

Returns:

this instance.
insert
(final int
the index to add at, must be valid.
index
,
String
the string to insert.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Inserts the string into this builder.

public boolean

Returns:

true if the size is 0.
isEmpty
()

Overrides default java.lang.CharSequence.isEmpty.

Checks is the string builder is empty (convenience Collections API style method).

public boolean

Returns:

true if the size is not 0.
isNotEmpty
()

Checks is the string builder is not empty.

public boolean

Returns:

Whether the internal buffer has been reallocated.
isReallocated
()

Gets whether the internal buffer has been reallocated.

public int

Returns:

The last index of the character, or -1 if not found.
lastIndexOf
(final char
the character to find.
ch
)

Searches the string builder to find the last reference to the specified char.

public int

Returns:

The last index of the character, or -1 if not found.
lastIndexOf
(final char
the character to find.
ch
,
int
the index to start at, invalid index rounded to edge.
startIndex
)

Searches the string builder to find the last reference to the specified char.

public int

Returns:

The last index of the string, or -1 if not found.
lastIndexOf
(final String
the string to find, null returns -1.
str
)

Searches the string builder to find the last reference to the specified string.

public int

Returns:

The last index of the string, or -1 if not found.
lastIndexOf
(final String
the string to find, null returns -1.
str
,
int
the index to start at, invalid index rounded to edge.
startIndex
)

Searches the string builder to find the last reference to the specified string starting searching from the given index.

public int

Returns:

The last index matched, or -1 if not found.
lastIndexOf
(final StringMatcher
the matcher to use, null returns -1.
matcher
)

Searches the string builder using the matcher to find the last match.

public int

Returns:

The last index matched, or -1 if not found.
lastIndexOf
(final StringMatcher
the matcher to use, null returns -1.
matcher
,
int
the index to start at, invalid index rounded to edge.
startIndex
)

Searches the string builder using the matcher to find the last match searching from the given index.

public String

Returns:

The new string.
leftString
(final int
the number of characters to extract, negative returns empty string.
length
)

Extracts the leftmost characters from the string builder without throwing an exception.

public int

Returns:

The length
length
()

Implements java.lang.CharSequence.length.

Gets the length of the string builder.

public String

Returns:

The new string.
midString
(int
the index to start at, negative means zero.
index
,
final int
the number of characters to extract, negative returns empty string.
length
)

Extracts some characters from the middle of the string builder without throwing an exception.

public TextStringBuilder

Returns:

this instance.
minimizeCapacity
()
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Minimizes the capacity to the actual length of the string.

public int

Returns:

The number of characters read.
readFrom
(final CharBuffer
CharBuffer to read.
charBuffer
)

If possible, reads chars from the provided CharBuffer directly into underlying character buffer without making extra copies.

public int

Returns:

The number of characters read.
readFrom
(final Readable
object to read from.
readable
)

If possible, reads all chars from the provided Readable directly into underlying character buffer without making extra copies.

public int

Returns:

The number of characters read or -1 if we reached the end of stream.
readFrom
(final Reader
Reader to read.
reader
)

If possible, reads all chars from the provided Reader directly into underlying character buffer without making extra copies.

public int

Returns:

The number of characters read. If less than count, then we've reached the end-of-stream, or -1 if we reached the end of stream.
readFrom
(final Reader
Reader to read.
reader
,
final int
The maximum characters to read, a value <= 0 returns 0.
count
)

If possible, reads count chars from the provided Reader directly into underlying character buffer without making extra copies.

private void
reallocate(final int
the length of the copy to be returned.
newLength
)

Reallocates the buffer to the new length.

public TextStringBuilder

Returns:

this instance.
replace
(final int
the start index, inclusive, must be valid.
startIndex
,
int
the end index, exclusive, must be valid except that if too large it is treated as end of string.
endIndex
,
final String
the string to replace with, null means delete range.
replaceStr
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Replaces a portion of the string builder with another string.

public TextStringBuilder

Returns:

this instance.
replace
(final StringMatcher
the matcher to use to find the deletion, null causes no action.
matcher
,
final String
the string to replace the match with, null is a delete.
replaceStr
,
final int
the start index, inclusive, must be valid.
startIndex
,
int
the end index, exclusive, must be valid except that if too large it is treated as end of string.
endIndex
,
final int
the number of times to replace, -1 for replace all.
replaceCount
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Advanced search and replaces within the builder using a matcher.

public TextStringBuilder

Returns:

this instance.
replaceAll
(final char
the search character.
search
,
final char
the replace character.
replace
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Replaces the search character with the replace character throughout the builder.

public TextStringBuilder

Returns:

this instance.
replaceAll
(final String
the search string, null causes no action to occur.
searchStr
,
final String
the replace string, null is equivalent to an empty string.
replaceStr
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Replaces the search string with the replace string throughout the builder.

public TextStringBuilder

Returns:

this instance.
replaceAll
(final StringMatcher
the matcher to use to find the deletion, null causes no action.
matcher
,
final String
the replace string, null is equivalent to an empty string.
replaceStr
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Replaces all matches within the builder with the replace string.

public TextStringBuilder

Returns:

this instance.
replaceFirst
(final char
the search character.
search
,
final char
the replace character.
replace
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Replaces the first instance of the search character with the replace character in the builder.

public TextStringBuilder

Returns:

this instance.
replaceFirst
(final String
the search string, null causes no action to occur.
searchStr
,
final String
the replace string, null is equivalent to an empty string.
replaceStr
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Replaces the first instance of the search string with the replace string.

public TextStringBuilder

Returns:

this instance.
replaceFirst
(final StringMatcher
the matcher to use to find the deletion, null causes no action.
matcher
,
final String
the replace string, null is equivalent to an empty string.
replaceStr
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Replaces the first match within the builder with the replace string.

private void
replaceImpl(final int
the start index, must be valid.
startIndex
,
final int
the end index (exclusive), must be valid.
endIndex
,
final int
the length to remove (endIndex - startIndex), must be valid.
removeLen
,
final String
the string to replace with, null means delete range.
insertStr
,
final int
the length of the insert string, must be valid.
insertLen
)

Internal method to delete a range without validation.

private TextStringBuilder

Returns:

this instance.
replaceImpl
(final StringMatcher
the matcher to use to find the deletion, null causes no action.
matcher
,
final String
the string to replace the match with, null is a delete.
replaceStr
,
final int
the start index, must be valid.
from
,
int
the end index (exclusive), must be valid.
to
,
int
the number of times to replace, -1 for replace all.
replaceCount
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Replaces within the builder using a matcher.

private void
resizeBuffer(final int
the minimum required capacity.
minCapacity
)

Resizes the buffer to at least the size specified.

public TextStringBuilder

Returns:

this instance.
reverse
()
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Reverses the string builder placing each character in the opposite index.

public String

Returns:

The new string.
rightString
(final int
the number of characters to extract, negative returns empty string.
length
)

Extracts the rightmost characters from the string builder without throwing an exception.

public TextStringBuilder

Returns:

this instance.
set
(final CharSequence
the new value.
str
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Clears and sets this builder to the given value.

public TextStringBuilder

Returns:

this instance.
setCharAt
(final int
the index to set
index
,
final char
the new character
ch
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Sets the character at the specified index.

public TextStringBuilder

Returns:

this instance.
setLength
(final int
the length to set to, must be zero or positive.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Updates the length of the builder by either dropping the last characters or adding filler of Unicode zero.

public TextStringBuilder

Returns:

this instance.
setNewLineText
(final String
the new line text, null means use the system default from System#lineSeparator().
newLine
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Sets the text to be appended when new line is called.

public TextStringBuilder

Returns:

this instance.
setNullText
(String
the null text, null means no append.
nullText
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Sets the text to be appended when null is added.

public int

Returns:

The length.
size
()

Gets the length of the string builder.

public boolean

Returns:

true if the builder starts with the string.
startsWith
(final String
the string to search for, null returns false.
str
)

Checks whether this builder starts with the specified string.

public CharSequence
subSequence(final int startIndex, final int endIndex)

Implements java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence.

public String

Returns:

The new string.
substring
(final int
the start index, inclusive, must be valid.
start
)

Extracts a portion of this string builder as a string.

public String

Returns:

The new string.
substring
(final int
the start index, inclusive, must be valid.
startIndex
,
int
the end index, exclusive, must be valid except that if too large it is treated as end of string.
endIndex
)

Extracts a portion of this string builder as a string.

public char[]

Returns:

a new array that represents the contents of the builder.
toCharArray
()

Copies the builder's character array into a new character array.

public char[]

Returns:

a new array that holds part of the contents of the builder.
toCharArray
(final int
the start index, inclusive, must be valid.
startIndex
,
int
the end index, exclusive, must be valid except that if too large it is treated as end of string.
endIndex
)

Copies part of the builder's character array into a new character array.

public String

Returns:

The builder as a String.
toString
()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Gets a String version of the string builder, creating a new instance each time the method is called.

public StringBuffer

Returns:

The builder as a StringBuffer.
toStringBuffer
()

Gets a StringBuffer version of the string builder, creating a new instance each time the method is called.

public StringBuilder

Returns:

The builder as a StringBuilder.
toStringBuilder
()

Gets a StringBuilder version of the string builder, creating a new instance each time the method is called.

public TextStringBuilder

Returns:

this instance.
trim
()
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Trims the builder by removing characters less than or equal to a space from the beginning and end.

protected void
validateIndex(final int
the index to test.
index
)

Validates that an index is in the range 0 <= index < size.

protected int

Returns:

A valid end index.
validateRange
(final int
the start index, inclusive, must be valid.
startIndex
,
int
the end index, exclusive, must be valid except that if too large it is treated as end of string.
endIndex
)

Validates parameters defining a range of the builder.

public static TextStringBuilder

Returns:

A new instance.
wrap
(final char[]
The initial array that will back the new builder.
initialBuffer
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Constructs an instance from a reference to a character array.

public static TextStringBuilder

Returns:

A new instance.
wrap
(final char[]
The initial array that will back the new builder.
initialBuffer
,
final int
The length of the subarray to be used; must be non-negative and no larger than initialBuffer.length. The new builder's size will be set to length.
length
)
References Deprecated TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.

Constructs an instance from a reference to a character array.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait