StrBuilder
- @Deprecated public class org.apache.commons.lang3.text.StrBuilder implements CharSequence, Appendable, Serializable, Builder<String>[source]
Deprecated: As of 3.6, use Apache Commons Text TextStringBuilder.
Builds a string from constituent parts providing a more flexible and powerful API than StringBuffer.
The main differences from StringBuffer/StringBuilder are:
Not synchronized
Not final
Subclasses have direct access to character array
Additional methods
appendWithSeparators - adds an array of values, with a separator
appendPadding - adds a length padding characters
appendFixedLength - adds a fixed width field to the builder
toCharArray/getChars - simpler ways to get a range of the character array
delete - delete char or string
replace - search and replace for a char or string
leftString/rightString/midString - substring without exceptions
contains - whether the builder contains a char or string
size/clear/isEmpty - collections style API methods
Views
asTokenizer - uses the internal buffer as the source of a StrTokenizer
asReader - uses the internal buffer as the source of a Reader
asWriter - allows a Writer to write directly to the internal buffer
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).Prior to 3.0, this class implemented Cloneable but did not implement the clone method so could not be used. From 3.0 onwards it no longer implements the interface.
- Since:
2.2
Constructors
Constructor that creates an empty builder initial capacity 32 characters. |
|
Constructor that creates an empty builder the specified initial capacity. |
|
Constructor that creates a builder from the string, allocating 32 extra characters for growth. |
- public StrBuilder()[source]
Constructor that creates an empty builder initial capacity 32 characters.
Fields and constants
Internal data storage. |
|
Current size of the buffer. |
Methods
Appends a boolean value to the string builder. |
|
Appends a char value to the string builder. |
|
Appends a char array to the string builder. |
|
Appends a char array to the string builder. |
|
Appends a double value to the string builder using |
|
Appends a float value to the string builder using |
|
Appends an int value to the string builder using |
|
Appends a CharSequence to this string builder. |
|
Appends part of a CharSequence to this string builder. |
|
Appends an object to this string builder. |
|
Appends a string to this string builder. |
|
Appends part of a string to this string builder. |
|
Calls |
|
Appends a string buffer to this string builder. |
|
Appends part of a string buffer to this string builder. |
|
Appends a StringBuilder to this string builder. |
|
Appends part of a StringBuilder to this string builder. |
|
Appends the contents of a char buffer to this string builder. |
|
Appends the contents of a char buffer to this string builder. |
|
Appends a long value to the string builder using |
|
Appends another string builder to this string builder. |
|
Appends part of a string builder to this string builder. |
|
Appends each item in an iterable to the builder without any separators. |
|
Appends each item in an array to the builder without any separators. |
|
Appends each item in an iterator to the builder without any separators. |
|
Appends an object to the builder padding on the left to a fixed width. |
|
Appends an object to the builder padding on the left to a fixed width. |
|
Appends an object to the builder padding on the right to a fixed length. |
|
Appends an object to the builder padding on the right to a fixed length. |
|
Appends this builder’s new line string to this builder. |
|
Appends the text representing |
|
Appends the pad character to the builder the specified number of times. |
|
Appends a separator if the builder is currently non-empty. |
|
Append 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 |
|
Appends a separator to the builder if the loop index is greater than zero. |
|
Appends a separator if the builder is currently non-empty. |
|
Appends a separator to the builder if the loop index is greater than zero. |
|
Appends one of both separators to the StrBuilder. |
|
Appends current contents of this |
|
Appends an iterable placing separators between each value, but not before the first or after the last. |
|
Appends an array placing separators between each value, but not before the first or after the last. |
|
Appends an iterator placing separators between each value, but not before the first or after the last. |
|
Appends a boolean value followed by a new line to the string builder. |
|
Appends a char value followed by a new line to the string builder. |
|
Appends a char array followed by a new line to the string builder. |
|
Appends a char array followed by a new line to the string builder. |
|
Appends a double value followed by a new line to the string builder using |
|
Appends a float value followed by a new line to the string builder using |
|
Appends an int value followed by a new line to the string builder using |
|
Appends an object followed by a new line to this string builder. |
|
Appends a string followed by a new line to this string builder. |
|
Appends part of a string followed by a new line to this string builder. |
|
Calls |
|
Appends a string buffer followed by a new line to this string builder. |
|
Appends part of a string buffer followed by a new line to this string builder. |
|
Appends a string builder followed by a new line to this string builder. |
|
Appends part of a string builder followed by a new line to this string builder. |
|
Appends a long value followed by a new line to the string builder using |
|
Appends another string builder followed by a new line to this string builder. |
|
Appends part of a string builder followed by a new line to this string builder. |
|
Gets the contents of this builder as a Reader. |
|
Creates a tokenizer that can tokenize the contents of this builder. |
|
Gets this builder as a Writer that can be written to. |
|
Implement the |
|
Gets the current size of the internal character array buffer. |
|
Gets the character at the specified index. |
|
Clears the string builder (convenience Collections API style method). |
|
Checks if the string builder contains the specified char. |
|
Checks if the string builder contains the specified string. |
|
Checks if the string builder contains a string matched using the specified matcher. |
|
Deletes the characters between the two specified indices. |
|
Deletes the character wherever it occurs in the builder. |
|
Deletes the string wherever it occurs in the builder. |
|
Deletes all parts of the builder that the matcher matches. |
|
Deletes the character at the specified index. |
|
Deletes the character wherever it occurs in the builder. |
|
Deletes the string wherever it occurs in the builder. |
|
Deletes the first match within the builder using the specified matcher. |
|
Checks whether this builder ends with the specified string. |
|
Checks the capacity and ensures that it is at least the size specified. |
|
Checks the contents of this builder against another to see if they contain the same character content. |
|
Checks the contents of this builder against another to see if they contain the same character content. |
|
Checks the contents of this builder against another to see if they contain the same character content ignoring case. |
|
Gets the characters by copying them into the specified array. |
|
Gets the characters by copying them into the specified array. |
|
Gets the text to be appended when a |
|
Gets the text to be appended when null is added. |
|
Gets a suitable hash code for this builder. |
|
Searches the string builder to find the first reference to the specified char. |
|
Searches the string builder to find the first reference to the specified char. |
|
Searches the string builder to find the first reference to the specified string. |
|
Searches the string builder to find the first reference to the specified string starting searching from the given index. |
|
Searches the string builder using the matcher to find the first match. |
|
Searches the string builder using the matcher to find the first match searching from the given index. |
|
Inserts the value into this builder. |
|
Inserts the value into this builder. |
|
Inserts the character array into this builder. |
|
Inserts part of the character array into this builder. |
|
Inserts the value into this builder. |
|
Inserts the value into this builder. |
|
Inserts the value into this builder. |
|
Inserts the string representation of an object into this builder. |
|
Inserts the string into this builder. |
|
Inserts the value into this builder. |
|
Tests whether the string builder is empty (convenience Collections API style method). |
|
Tests whether the string builder is not empty (convenience Collections API style method). |
|
Searches the string builder to find the last reference to the specified char. |
|
Searches the string builder to find the last reference to the specified char. |
|
Searches the string builder to find the last reference to the specified string. |
|
Searches the string builder to find the last reference to the specified string starting searching from the given index. |
|
Searches the string builder using the matcher to find the last match. |
|
Searches the string builder using the matcher to find the last match searching from the given index. |
|
Extracts the leftmost characters from the string builder without throwing an exception. |
|
Gets the length of the string builder. |
|
Extracts some characters from the middle of the string builder without throwing an exception. |
|
Minimizes the capacity to the actual length of the string. |
|
If possible, reads chars from the provided |
|
Replaces a portion of the string builder with another string. |
|
Advanced search and replaces within the builder using a matcher. |
|
Replaces the search character with the replace character throughout the builder. |
|
Replaces the search string with the replace string throughout the builder. |
|
Replaces all matches within the builder with the replace string. |
|
Replaces the first instance of the search character with the replace character in the builder. |
|
Replaces the first instance of the search string with the replace string. |
|
Replaces the first match within the builder with the replace string. |
|
Reverses the string builder placing each character in the opposite index. |
|
Extracts the rightmost characters from the string builder without throwing an exception. |
|
Sets the character at the specified index. |
|
Sets the length of the builder by removing trailing characters or adding Unicode zero characters. |
|
Sets the text to be appended when |
|
Sets the text to be appended when null is added. |
|
Gets the length of the string builder. |
|
Checks whether this builder starts with the specified string. |
|
[unresolved inheritDoc] |
|
Extracts a portion of this string builder as a string. |
|
Extracts a portion of this string builder as a string. |
|
Copies the builder’s character array into a new character array. |
|
Copies part of the builder’s character array into a new character array. |
|
Gets a String version of the string builder, creating a new instance each time the method is called. |
|
Gets a StringBuffer version of the string builder, creating a new instance each time the method is called. |
|
Gets a StringBuilder version of the string builder, creating a new instance each time the method is called. |
|
Trims the builder by removing characters less than or equal to a space from the beginning and end. |
|
Validates parameters defining a single index in the builder. |
|
Validates parameters defining a range of the builder. |
- public StrBuilder append(boolean value)[source]
Appends a boolean value to the string builder.
- Parameters:
value – The value to append.
- Returns:
thisinstance.
- @Override public StrBuilder append(char ch)[source]
Appends a char value to the string builder.
- Parameters:
ch – The value to append.
- Returns:
thisinstance.- Since:
3.0
- public StrBuilder append(char[] chars)[source]
Appends a char array to the string builder. Appending null will call
#appendNull().- Parameters:
chars – The char array to append.
- Returns:
thisinstance.
- public StrBuilder append(char[] chars, int startIndex, int length)[source]
Appends a char array to the string builder. Appending null will call
#appendNull().- Parameters:
chars – The char array to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.
- public StrBuilder append(double value)[source]
Appends a double value to the string builder using
String.valueOf.- Parameters:
value – The value to append.
- Returns:
thisinstance.
- public StrBuilder append(float value)[source]
Appends a float value to the string builder using
String.valueOf.- Parameters:
value – The value to append.
- Returns:
thisinstance.
- public StrBuilder append(int value)[source]
Appends an int value to the string builder using
String.valueOf.- Parameters:
value – The value to append.
- Returns:
thisinstance.
- @Override public StrBuilder append(CharSequence seq)[source]
Appends a CharSequence to this string builder. Appending null will call
#appendNull().- Parameters:
seq – The CharSequence to append.
- Returns:
thisinstance.- Since:
3.0
- @Override public StrBuilder append(CharSequence seq, int startIndex, int length)[source]
Appends part of a CharSequence to this string builder. Appending null will call
#appendNull().- Parameters:
seq – The CharSequence to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.- Since:
3.0
- public StrBuilder append(Object obj)[source]
Appends an object to this string builder. Appending null will call
#appendNull().- Parameters:
obj – The object to append.
- Returns:
thisinstance.
- public StrBuilder append(String str)[source]
Appends a string to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string to append.
- Returns:
thisinstance.
- public StrBuilder append(String str, int startIndex, int length)[source]
Appends part of a string to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.
- public StrBuilder append(String format, Object... objs)[source]
Calls
String#format(String, Object...)and appends the result.- Parameters:
format – The format string.
objs – The objects to use in the format string.
- Returns:
thisto enable chaining.- See also:
- Since:
3.2
- public StrBuilder append(StringBuffer str)[source]
Appends a string buffer to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string buffer to append.
- Returns:
thisinstance.
- public StrBuilder append(StringBuffer str, int startIndex, int length)[source]
Appends part of a string buffer to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.
- public StrBuilder append(StringBuilder str)[source]
Appends a StringBuilder to this string builder. Appending null will call
#appendNull().- Parameters:
str – The StringBuilder to append.
- Returns:
thisinstance.- Since:
3.2
- public StrBuilder append(StringBuilder str, int startIndex, int length)[source]
Appends part of a StringBuilder to this string builder. Appending null will call
#appendNull().- Parameters:
str – The StringBuilder to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.- Since:
3.2
- public StrBuilder append(CharBuffer buf)[source]
Appends the contents of a char buffer to this string builder. Appending null will call
#appendNull().- Parameters:
buf – The char buffer to append.
- Returns:
thisinstance.- Since:
3.4
- public StrBuilder append(CharBuffer buf, int startIndex, int length)[source]
Appends the contents of a char buffer to this string builder. Appending null will call
#appendNull().- Parameters:
buf – The char buffer to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.- Since:
3.4
- public StrBuilder append(long value)[source]
Appends a long value to the string builder using
String.valueOf.- Parameters:
value – The value to append.
- Returns:
thisinstance.
- public StrBuilder append(StrBuilder str)[source]
Appends another string builder to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string builder to append.
- Returns:
thisinstance.
- public StrBuilder append(StrBuilder str, int startIndex, int length)[source]
Appends part of a string builder to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.
- public StrBuilder appendAll(Iterable<?> iterable)[source]
Appends each item in an iterable to the builder without any separators. Appending a null iterable will have no effect. Each object is appended using
#append(Object).- Parameters:
iterable – The iterable to append.
- Returns:
thisinstance.- Since:
2.3
- public <T> StrBuilder appendAll(@SuppressWarnings({"unchecked"}) T... array)[source]
Appends each item in an array to the builder without any separators. Appending a null array will have no effect. Each object is appended using
#append(Object).- Type parameters:
<T> – the element type.
- Parameters:
array – The array to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendAll(Iterator<?> it)[source]
Appends each item in an iterator to the builder without any separators. Appending a null iterator will have no effect. Each object is appended using
#append(Object).- Parameters:
it – The iterator to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendFixedWidthPadLeft(int value, int width, char padChar)[source]
Appends an object to the builder padding on the left to a fixed width. The
String.valueOfof theintvalue is used. If the formatted value is larger than the length, the left-hand side is lost.- Parameters:
value – The value to append.
width – The fixed field width, zero or negative has no effect.
padChar – The pad character to use.
- Returns:
thisinstance.
- public StrBuilder appendFixedWidthPadLeft(Object obj, int width, char padChar)[source]
Appends an object to the builder padding on the left to a fixed width. The
toStringof the object is used. If the object is larger than the length, the left-hand side is lost. If the object is null, the null text value is used.- Parameters:
obj – The object to append, null uses null text.
width – The fixed field width, zero or negative has no effect.
padChar – The pad character to use.
- Returns:
thisinstance.
- public StrBuilder appendFixedWidthPadRight(int value, int width, char padChar)[source]
Appends an object to the builder padding on the right to a fixed length. The
String.valueOfof theintvalue is used. If the object is larger than the length, the right-hand side is lost.- Parameters:
value – The value to append.
width – The fixed field width, zero or negative has no effect.
padChar – The pad character to use.
- Returns:
thisinstance.
- public StrBuilder appendFixedWidthPadRight(Object obj, int width, char padChar)[source]
Appends an object to the builder padding on the right to a fixed length. The
toStringof the object is used. If the object is larger than the length, the right-hand side is lost. If the object is null, null text value is used.- Parameters:
obj – The object to append, null uses null text.
width – The fixed field width, zero or negative has no effect.
padChar – The pad character to use.
- Returns:
thisinstance.
- public StrBuilder appendNewLine()[source]
Appends this builder’s new line string to this builder.
By default, the new line is the system default from
System#lineSeparator().The new line string can be changed using
#setNewLineText(String). For example, you can use this to force the output to always use Unix line endings even when on Windows.- Returns:
thisinstance.- See also:
- public StrBuilder appendNull()[source]
Appends the text representing
nullto this string builder.- Returns:
thisinstance.
- public StrBuilder appendPadding(int length, char padChar)[source]
Appends the pad character to the builder the specified number of times.
- Parameters:
length – The length to append, negative means no append.
padChar – The character to append.
- Returns:
thisinstance.
- public StrBuilder appendSeparator(char separator)[source]
Appends a separator if the builder is currently non-empty. The separator is appended using
#append(char).This method is useful for adding a separator each time around the loop except the first.
for (Iterator it = list.iterator(); it.hasNext(); ) { appendSeparator(','); append(it.next()); }
Note that for this simple example, you should use
#appendWithSeparators(Iterable, String).- Parameters:
separator – The separator to use.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendSeparator(char standard, char defaultIfEmpty)[source]
Append 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).- Parameters:
standard – The separator if builder is not empty.
defaultIfEmpty – The separator if builder is empty.
- Returns:
thisinstance.- Since:
2.5
- public StrBuilder appendSeparator(char separator, int loopIndex)[source]
Appends a separator to the builder if the loop index is greater than zero. The separator is appended using
#append(char).This method is useful for adding a separator each time around the loop except the first.
for (int i = 0; i < list.size(); i++) { appendSeparator(",", i); append(list.get(i)); }
Note that for this simple example, you should use
#appendWithSeparators(Iterable, String).- Parameters:
separator – The separator to use.
loopIndex – The loop index.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendSeparator(String separator)[source]
Appends a separator if the builder is currently non-empty. Appending a null separator will have no effect. The separator is appended using
#append(String).This method is useful for adding a separator each time around the loop except the first.
for (Iterator it = list.iterator(); it.hasNext(); ) { appendSeparator(","); append(it.next()); }
Note that for this simple example, you should use
#appendWithSeparators(Iterable, String).- Parameters:
separator – The separator to use, null means no separator.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendSeparator(String separator, int loopIndex)[source]
Appends a separator to the builder if the loop index is greater than zero. Appending a null separator will have no effect. The separator is appended using
#append(String).This method is useful for adding a separator each time around the loop except the first.
for (int i = 0; i < list.size(); i++) { appendSeparator(",", i); append(list.get(i)); }
Note that for this simple example, you should use
#appendWithSeparators(Iterable, String).- Parameters:
separator – The separator to use, null means no separator.
loopIndex – The loop index.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendSeparator(String standard, String defaultIfEmpty)[source]
Appends one of both separators to the StrBuilder. If the builder is currently empty it will append the defaultIfEmpty-separator Otherwise it will append the standard-separator
Appending a null separator will have no effect. The separator is appended using
#append(String).This method is for example useful for constructing queries
StrBuilder whereClause = new StrBuilder(); if (searchCommand.getPriority() != null) { whereClause.appendSeparator(" and", " where"); whereClause.append(" priority = ?") } if (searchCommand.getComponent() != null) { whereClause.appendSeparator(" and", " where"); whereClause.append(" component = ?") } selectClause.append(whereClause)
- Parameters:
standard – The separator if builder is not empty, null means no separator.
defaultIfEmpty – The separator if builder is empty, null means no separator.
- Returns:
thisinstance.- Since:
2.5
- public void appendTo(Appendable appendable) throws IOException[source]
Appends current contents of this
StrBuilderto the providedAppendable.This method tries to avoid doing any extra copies of contents.
- Parameters:
appendable – The appendable to append data to
- Throws:
java.io.IOException – Thrown if an I/O error occurs.
- Since:
3.4
- See also:
- public StrBuilder appendWithSeparators(Iterable<?> iterable, String separator)[source]
Appends an iterable placing separators between each value, but not before the first or after the last. Appending a null iterable will have no effect. Each object is appended using
#append(Object).- Parameters:
iterable – The iterable to append.
separator – The separator to use, null means no separator.
- Returns:
thisinstance.
- public StrBuilder appendWithSeparators(Object[] array, String separator)[source]
Appends an array placing separators between each value, but not before the first or after the last. Appending a null array will have no effect. Each object is appended using
#append(Object).- Parameters:
array – The array to append.
separator – The separator to use, null means no separator.
- Returns:
thisinstance.
- public StrBuilder appendWithSeparators(Iterator<?> it, String separator)[source]
Appends an iterator placing separators between each value, but not before the first or after the last. Appending a null iterator will have no effect. Each object is appended using
#append(Object).- Parameters:
it – The iterator to append.
separator – The separator to use, null means no separator.
- Returns:
thisinstance.
- public StrBuilder appendln(boolean value)[source]
Appends a boolean value followed by a new line to the string builder.
- Parameters:
value – The value to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(char ch)[source]
Appends a char value followed by a new line to the string builder.
- Parameters:
ch – The value to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(char[] chars)[source]
Appends a char array followed by a new line to the string builder. Appending null will call
#appendNull().- Parameters:
chars – The char array to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(char[] chars, int startIndex, int length)[source]
Appends a char array followed by a new line to the string builder. Appending null will call
#appendNull().- Parameters:
chars – The char array to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(double value)[source]
Appends a double value followed by a new line to the string builder using
String.valueOf.- Parameters:
value – The value to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(float value)[source]
Appends a float value followed by a new line to the string builder using
String.valueOf.- Parameters:
value – The value to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(int value)[source]
Appends an int value followed by a new line to the string builder using
String.valueOf.- Parameters:
value – The value to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(Object obj)[source]
Appends an object followed by a new line to this string builder. Appending null will call
#appendNull().- Parameters:
obj – The object to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(String str)[source]
Appends a string followed by a new line to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(String str, int startIndex, int length)[source]
Appends part of a string followed by a new line to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(String format, Object... objs)[source]
Calls
String#format(String, Object...)and appends the result.- Parameters:
format – The format string.
objs – The objects to use in the format string.
- Returns:
thisto enable chaining.- See also:
- Since:
3.2
- public StrBuilder appendln(StringBuffer str)[source]
Appends a string buffer followed by a new line to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string buffer to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(StringBuffer str, int startIndex, int length)[source]
Appends part of a string buffer followed by a new line to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(StringBuilder str)[source]
Appends a string builder followed by a new line to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string builder to append.
- Returns:
thisinstance.- Since:
3.2
- public StrBuilder appendln(StringBuilder str, int startIndex, int length)[source]
Appends part of a string builder followed by a new line to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string builder to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.- Since:
3.2
- public StrBuilder appendln(long value)[source]
Appends a long value followed by a new line to the string builder using
String.valueOf.- Parameters:
value – The value to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(StrBuilder str)[source]
Appends another string builder followed by a new line to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string builder to append.
- Returns:
thisinstance.- Since:
2.3
- public StrBuilder appendln(StrBuilder str, int startIndex, int length)[source]
Appends part of a string builder followed by a new line to this string builder. Appending null will call
#appendNull().- Parameters:
str – The string to append.
startIndex – The start index, inclusive, must be valid.
length – The length to append, must be valid.
- Returns:
thisinstance.- Since:
2.3
- public Reader asReader()[source]
Gets the contents of this builder as a Reader.
This method allows the contents of the builder to be read using any standard method that expects a Reader.
To use, simply create a
StrBuilder, populate it with data, callasReader, and then read away.The internal character array is shared between the builder and the reader. This allows you to append to the builder after creating the reader, and the changes will be picked up. Note however, that no synchronization occurs, so you must perform all operations with the builder and the reader in one thread.
The returned reader supports marking, and ignores the flush method.
- Returns:
A reader that reads from this builder.
- public StrTokenizer asTokenizer()[source]
Creates a tokenizer that can tokenize the contents of this builder.
This method allows the contents of this builder to be tokenized. The tokenizer will be setup by default to tokenize on space, tab, newline and formfeed (as per StringTokenizer). These values can be changed on the tokenizer class, before retrieving the tokens.
The returned tokenizer is linked to this builder. You may intermix calls to the builder and tokenizer within certain limits, however there is no synchronization. Once the tokenizer has been used once, it must be
resetto pickup the latest changes in the builder. For example:StrBuilder b = new StrBuilder(); b.append("a b "); StrTokenizer t = b.asTokenizer(); String[] tokens1 = t.getTokenArray(); // returns a,b b.append("c d "); String[] tokens2 = t.getTokenArray(); // returns a,b (c and d ignored) t.reset(); // reset causes builder changes to be picked up String[] tokens3 = t.getTokenArray(); // returns a,b,c,d
In addition to simply intermixing appends and tokenization, you can also call the set methods on the tokenizer to alter how it tokenizes. Just remember to call reset when you want to pickup builder changes.
Calling
StrTokenizer#reset(String)orStrTokenizer#reset(char[])with a non-null value will break the link with the builder.- Returns:
A tokenizer that is linked to this builder.
- public Writer asWriter()[source]
Gets this builder as a Writer that can be written to.
This method allows you to populate the contents of the builder using any standard method that takes a Writer.
To use, simply create a
StrBuilder, callasWriter, and populate away. The data is available at any time using the methods of theStrBuilder.The internal character array is shared between the builder and the writer. This allows you to intermix calls that append to the builder and write using the writer and the changes will be occur correctly. Note however, that no synchronization occurs, so you must perform all operations with the builder and the writer in one thread.
The returned writer ignores the close and flush methods.
- Returns:
A writer that populates this builder
- @Override public String build()[source]
Implement the
Builderinterface.- Returns:
The builder as a String
- Since:
3.2
- See also:
- public int capacity()[source]
Gets the current size of the internal character array buffer.
- Returns:
The capacity.
- @Override public char charAt(int index)[source]
Gets the character at the specified index.
- Parameters:
index – The index to retrieve, must be valid.
- Returns:
The character at the index.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- See also:
- public StrBuilder clear()[source]
Clears the string builder (convenience Collections API style method).
This method does not reduce the size of the internal character buffer. To do that, call
clear()followed by#minimizeCapacity().- Returns:
thisinstance.
- public boolean contains(char ch)[source]
Checks if the string builder contains the specified char.
- Parameters:
ch – The character to find.
- Returns:
true if the builder contains the character.
- public boolean contains(String str)[source]
Checks if the string builder contains the specified string.
- Parameters:
str – The string to find.
- Returns:
true if the builder contains the string.
- public boolean contains(StrMatcher matcher)[source]
Checks if the string builder contains a string matched using the specified matcher.
Matchers can be used to perform advanced searching behavior. For example you could write a matcher to search for the character ‘a’ followed by a number.
- Parameters:
matcher – The matcher to use, null returns -1.
- Returns:
true if the matcher finds a match in the builder.
- public StrBuilder delete(int startIndex, int endIndex)[source]
Deletes the characters between the two specified indices.
- Parameters:
startIndex – The start index, inclusive, must be valid.
endIndex – The end index, exclusive, must be valid except that if too large it is treated as end of string.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public StrBuilder deleteAll(char ch)[source]
Deletes the character wherever it occurs in the builder.
- Parameters:
ch – The character to delete.
- Returns:
thisinstance.
- public StrBuilder deleteAll(String str)[source]
Deletes the string wherever it occurs in the builder.
- Parameters:
str – The string to delete, null causes no action.
- Returns:
thisinstance.
- public StrBuilder deleteAll(StrMatcher matcher)[source]
Deletes all parts of the builder that the matcher matches.
Matchers can be used to perform advanced deletion behavior. For example you could write a matcher to delete all occurrences where the character ‘a’ is followed by a number.
- Parameters:
matcher – The matcher to use to find the deletion, null causes no action.
- Returns:
thisinstance.
- public StrBuilder deleteCharAt(int index)[source]
Deletes the character at the specified index.
- Parameters:
index – The index to delete.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- See also:
- public StrBuilder deleteFirst(char ch)[source]
Deletes the character wherever it occurs in the builder.
- Parameters:
ch – The character to delete.
- Returns:
thisinstance.
- public StrBuilder deleteFirst(String str)[source]
Deletes the string wherever it occurs in the builder.
- Parameters:
str – The string to delete, null causes no action.
- Returns:
thisinstance.
- public StrBuilder deleteFirst(StrMatcher matcher)[source]
Deletes the first match within the builder using the specified matcher.
Matchers can be used to perform advanced deletion behavior. For example you could write a matcher to delete where the character ‘a’ is followed by a number.
- Parameters:
matcher – The matcher to use to find the deletion, null causes no action.
- Returns:
thisinstance.
- public boolean endsWith(String str)[source]
Checks whether this builder ends with the specified string.
Note that this method handles null input quietly, unlike String.
- Parameters:
str – The string to search for, null returns false.
- Returns:
true if the builder ends with the string.
- public StrBuilder ensureCapacity(int capacity)[source]
Checks the capacity and ensures that it is at least the size specified.
- Parameters:
capacity – The capacity to ensure.
- Returns:
thisinstance.
- @Override public boolean equals(Object obj)[source]
Checks the contents of this builder against another to see if they contain the same character content.
- Parameters:
obj – The object to check, null returns false.
- Returns:
true if the builders contain the same characters in the same order.
- public boolean equals(StrBuilder other)[source]
Checks the contents of this builder against another to see if they contain the same character content.
- Parameters:
other – The object to check, null returns false.
- Returns:
true if the builders contain the same characters in the same order.
- public boolean equalsIgnoreCase(StrBuilder other)[source]
Checks the contents of this builder against another to see if they contain the same character content ignoring case.
- Parameters:
other – The object to check, null returns false.
- Returns:
true if the builders contain the same characters in the same order.
- public char[] getChars(char[] destination)[source]
Gets the characters by copying them into the specified array.
- Parameters:
destination – The destination array, null will cause an array to be created.
- Returns:
The input array, unless that was null or too small.
- public void getChars(int startIndex, int endIndex, char[] destination, int destinationIndex)[source]
Gets the characters by copying them into the specified array.
- Parameters:
startIndex – first index to copy, inclusive, must be valid.
endIndex – last index, exclusive, must be valid.
destination – The destination array, must not be null or too small.
destinationIndex – The index to start copying in destination.
- Throws:
java.lang.NullPointerException – Thrown if the array is null.
java.lang.IndexOutOfBoundsException – Thrown if any index is invalid.
- public String getNewLineText()[source]
Gets the text to be appended when a
new lineis added.- Returns:
The new line text,
nullmeans use the system default fromSystem#lineSeparator().
- public String getNullText()[source]
Gets the text to be appended when null is added.
- Returns:
The null text, null means no append.
- @Override public int hashCode()[source]
Gets a suitable hash code for this builder.
- Returns:
A hash code.
- public int indexOf(char ch)[source]
Searches the string builder to find the first reference to the specified char.
- Parameters:
ch – The character to find.
- Returns:
The first index of the character, or -1 if not found.
- public int indexOf(char ch, int startIndex)[source]
Searches the string builder to find the first reference to the specified char.
- Parameters:
ch – The character to find.
startIndex – The index to start at, invalid index rounded to edge.
- Returns:
The first index of the character, or -1 if not found.
- public int indexOf(String str)[source]
Searches the string builder to find the first reference to the specified string.
Note that a null input string will return -1, whereas the JDK throws an exception.
- Parameters:
str – The string to find, null returns -1.
- Returns:
The first index of the string, or -1 if not found.
- public int indexOf(String str, int startIndex)[source]
Searches the string builder to find the first reference to the specified string starting searching from the given index.
Note that a null input string will return -1, whereas the JDK throws an exception.
- Parameters:
str – The string to find, null returns -1.
startIndex – The index to start at, invalid index rounded to edge.
- Returns:
The first index of the string, or -1 if not found.
- public int indexOf(StrMatcher matcher)[source]
Searches the string builder using the matcher to find the first match.
Matchers can be used to perform advanced searching behavior. For example you could write a matcher to find the character ‘a’ followed by a number.
- Parameters:
matcher – The matcher to use, null returns -1.
- Returns:
The first index matched, or -1 if not found.
- public int indexOf(StrMatcher matcher, int startIndex)[source]
Searches the string builder using the matcher to find the first match searching from the given index.
Matchers can be used to perform advanced searching behavior. For example you could write a matcher to find the character ‘a’ followed by a number.
- Parameters:
matcher – The matcher to use, null returns -1.
startIndex – The index to start at, invalid index rounded to edge.
- Returns:
The first index matched, or -1 if not found.
- public StrBuilder insert(int index, boolean value)[source]
Inserts the value into this builder.
- Parameters:
index – The index to add at, must be valid.
value – The value to insert.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public StrBuilder insert(int index, char value)[source]
Inserts the value into this builder.
- Parameters:
index – The index to add at, must be valid.
value – The value to insert.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public StrBuilder insert(int index, char[] chars)[source]
Inserts the character array into this builder. Inserting null will use the stored null text value.
- Parameters:
index – The index to add at, must be valid.
chars – The char array to insert.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public StrBuilder insert(int index, char[] chars, int offset, int length)[source]
Inserts part of the character array into this builder. Inserting null will use the stored null text value.
- Parameters:
index – The index to add at, must be valid.
chars – The char array to insert.
offset – The offset into the character array to start at, must be valid.
length – The length of the character array part to copy, must be positive.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if any index is invalid.
- public StrBuilder insert(int index, double value)[source]
Inserts the value into this builder.
- Parameters:
index – The index to add at, must be valid.
value – The value to insert.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public StrBuilder insert(int index, float value)[source]
Inserts the value into this builder.
- Parameters:
index – The index to add at, must be valid.
value – The value to insert.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public StrBuilder insert(int index, int value)[source]
Inserts the value into this builder.
- Parameters:
index – The index to add at, must be valid.
value – The value to insert.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public StrBuilder insert(int index, Object obj)[source]
Inserts the string representation of an object into this builder. Inserting null will use the stored null text value.
- Parameters:
index – The index to add at, must be valid.
obj – The object to insert.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public StrBuilder insert(int index, String str)[source]
Inserts the string into this builder. Inserting null will use the stored null text value.
- Parameters:
index – The index to add at, must be valid.
str – The string to insert.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public StrBuilder insert(int index, long value)[source]
Inserts the value into this builder.
- Parameters:
index – The index to add at, must be valid.
value – The value to insert.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public boolean isEmpty()[source]
Tests whether the string builder is empty (convenience Collections API style method).
This method is the same as checking
#length()and is provided to match the API of Collections.- Returns:
trueif the size is0.
- public boolean isNotEmpty()[source]
Tests whether the string builder is not empty (convenience Collections API style method).
This method is the same as checking
#length()and is provided to match the API of Collections.- Returns:
trueif the size is greater than0.- Since:
3.12.0
- public int lastIndexOf(char ch)[source]
Searches the string builder to find the last reference to the specified char.
- Parameters:
ch – The character to find.
- Returns:
The last index of the character, or -1 if not found.
- public int lastIndexOf(char ch, int startIndex)[source]
Searches the string builder to find the last reference to the specified char.
- Parameters:
ch – The character to find.
startIndex – The index to start at, invalid index rounded to edge.
- Returns:
The last index of the character, or -1 if not found.
- public int lastIndexOf(String str)[source]
Searches the string builder to find the last reference to the specified string.
Note that a null input string will return -1, whereas the JDK throws an exception.
- Parameters:
str – The string to find, null returns -1.
- Returns:
The last index of the string, or -1 if not found.
- public int lastIndexOf(String str, int startIndex)[source]
Searches the string builder to find the last reference to the specified string starting searching from the given index.
Note that a null input string will return -1, whereas the JDK throws an exception.
- Parameters:
str – The string to find, null returns -1.
startIndex – The index to start at, invalid index rounded to edge.
- Returns:
The last index of the string, or -1 if not found.
- public int lastIndexOf(StrMatcher matcher)[source]
Searches the string builder using the matcher to find the last match.
Matchers can be used to perform advanced searching behavior. For example you could write a matcher to find the character ‘a’ followed by a number.
- Parameters:
matcher – The matcher to use, null returns -1.
- Returns:
The last index matched, or -1 if not found.
- public int lastIndexOf(StrMatcher matcher, int startIndex)[source]
Searches the string builder using the matcher to find the last match searching from the given index.
Matchers can be used to perform advanced searching behavior. For example you could write a matcher to find the character ‘a’ followed by a number.
- Parameters:
matcher – The matcher to use, null returns -1.
startIndex – The index to start at, invalid index rounded to edge.
- Returns:
The last index matched, or -1 if not found.
- public String leftString(int length)[source]
Extracts the leftmost characters from the string builder without throwing an exception.
This method extracts the left
lengthcharacters from the builder. If this many characters are not available, the whole builder is returned. Thus the returned string may be shorter than the length requested.- Parameters:
length – The number of characters to extract, negative returns empty string.
- Returns:
The new string.
- public String midString(int index, int length)[source]
Extracts some characters from the middle of the string builder without throwing an exception.
This method extracts
lengthcharacters from the builder at the specified index. If the index is negative it is treated as zero. If the index is greater than the builder size, it is treated as the builder size. If the length is negative, the empty string is returned. If insufficient characters are available in the builder, as much as possible is returned. Thus the returned string may be shorter than the length requested.- Parameters:
index – The index to start at, negative means zero.
length – The number of characters to extract, negative returns empty string.
- Returns:
The new string.
- public StrBuilder minimizeCapacity()[source]
Minimizes the capacity to the actual length of the string.
- Returns:
thisinstance.
- public int readFrom(Readable readable) throws IOException[source]
If possible, reads chars from the provided
Readabledirectly into underlying character buffer without making extra copies.- Parameters:
readable – object to read from.
- Returns:
The number of characters read.
- Throws:
java.io.IOException – Thrown if an I/O error occurs.
- Since:
3.4
- See also:
- public StrBuilder replace(int startIndex, int endIndex, String replaceStr)[source]
Replaces a portion of the string builder with another string. The length of the inserted string does not have to match the removed length.
- Parameters:
startIndex – The start index, inclusive, must be valid.
endIndex – The end index, exclusive, must be valid except that if too large it is treated as end of string.
replaceStr – The string to replace with, null means delete range.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public StrBuilder replace(StrMatcher matcher, String replaceStr, int startIndex, int endIndex, int replaceCount)[source]
Advanced search and replaces within the builder using a matcher.
Matchers can be used to perform advanced behavior. For example you could write a matcher to delete all occurrences where the character ‘a’ is followed by a number.
- Parameters:
matcher – The matcher to use to find the deletion, null causes no action.
replaceStr – The string to replace the match with, null is a delete.
startIndex – The start index, inclusive, must be valid.
endIndex – The end index, exclusive, must be valid except that if too large it is treated as end of string.
replaceCount – The number of times to replace, -1 for replace all.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if start index is invalid.
- public StrBuilder replaceAll(char search, char replace)[source]
Replaces the search character with the replace character throughout the builder.
- Parameters:
search – The search character.
replace – The replace character.
- Returns:
thisinstance.
- public StrBuilder replaceAll(String searchStr, String replaceStr)[source]
Replaces the search string with the replace string throughout the builder.
- Parameters:
searchStr – The search string, null causes no action to occur.
replaceStr – The replace string, null is equivalent to an empty string.
- Returns:
thisinstance.
- public StrBuilder replaceAll(StrMatcher matcher, String replaceStr)[source]
Replaces all matches within the builder with the replace string.
Matchers can be used to perform advanced replace behavior. For example you could write a matcher to replace all occurrences where the character ‘a’ is followed by a number.
- Parameters:
matcher – The matcher to use to find the deletion, null causes no action.
replaceStr – The replace string, null is equivalent to an empty string.
- Returns:
thisinstance.
- public StrBuilder replaceFirst(char search, char replace)[source]
Replaces the first instance of the search character with the replace character in the builder.
- Parameters:
search – The search character.
replace – The replace character.
- Returns:
thisinstance.
- public StrBuilder replaceFirst(String searchStr, String replaceStr)[source]
Replaces the first instance of the search string with the replace string.
- Parameters:
searchStr – The search string, null causes no action to occur.
replaceStr – The replace string, null is equivalent to an empty string.
- Returns:
thisinstance.
- public StrBuilder replaceFirst(StrMatcher matcher, String replaceStr)[source]
Replaces the first match within the builder with the replace string.
Matchers can be used to perform advanced replace behavior. For example you could write a matcher to replace where the character ‘a’ is followed by a number.
- Parameters:
matcher – The matcher to use to find the deletion, null causes no action.
replaceStr – The replace string, null is equivalent to an empty string.
- Returns:
thisinstance.
- public StrBuilder reverse()[source]
Reverses the string builder placing each character in the opposite index.
- Returns:
thisinstance.
- public String rightString(int length)[source]
Extracts the rightmost characters from the string builder without throwing an exception.
This method extracts the right
lengthcharacters from the builder. If this many characters are not available, the whole builder is returned. Thus the returned string may be shorter than the length requested.- Parameters:
length – The number of characters to extract, negative returns empty string.
- Returns:
The new string.
- public StrBuilder setCharAt(int index, char ch)[source]
Sets the character at the specified index.
- Parameters:
index – The index to set.
ch – The new character.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- See also:
- public StrBuilder setLength(int length)[source]
Sets the length of the builder by removing trailing characters or adding Unicode zero characters.
- Parameters:
length – The length to set to, must be zero or positive.
- Returns:
thisinstance.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the length is negative.
- public StrBuilder setNewLineText(String newLine)[source]
Sets the text to be appended when
new lineis called.- Parameters:
newLine – The new line text,
nullmeans use the system default fromSystem#lineSeparator().- Returns:
thisinstance.
- public StrBuilder setNullText(String nullText)[source]
Sets the text to be appended when null is added.
- Parameters:
nullText – The null text, null means no append.
- Returns:
thisinstance.
- public int size()[source]
Gets the length of the string builder.
This method is the same as
#length()and is provided to match the API of Collections.- Returns:
The length.
- public boolean startsWith(String str)[source]
Checks whether this builder starts with the specified string.
Note that this method handles null input quietly, unlike String.
- Parameters:
str – The string to search for, null returns false.
- Returns:
true if the builder starts with the string.
- @Override public CharSequence subSequence(int startIndex, int endIndex)[source]
[unresolved inheritDoc]
- Since:
3.0
- public String substring(int start)[source]
Extracts a portion of this string builder as a string.
- Parameters:
start – The start index, inclusive, must be valid.
- Returns:
The new string.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public String substring(int startIndex, int endIndex)[source]
Extracts a portion of this string builder as a string.
Note: This method treats an endIndex greater than the length of the builder as equal to the length of the builder, and continues without error, unlike StringBuffer or String.
- Parameters:
startIndex – The start index, inclusive, must be valid.
endIndex – The end index, exclusive, must be valid except that if too large it is treated as end of string.
- Returns:
The new string.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- public char[] toCharArray()[source]
Copies the builder’s character array into a new character array.
- Returns:
A new array that represents the contents of the builder.
- public char[] toCharArray(int startIndex, int endIndex)[source]
Copies part of the builder’s character array into a new character array.
- Parameters:
startIndex – The start index, inclusive, must be valid.
endIndex – The end index, exclusive, must be valid except that if too large it is treated as end of string.
- Returns:
A new array that holds part of the contents of the builder.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if startIndex is invalid, or if endIndex is invalid (but endIndex greater than size is valid).
- @Override public String toString()[source]
Gets a String version of the string builder, creating a new instance each time the method is called.
Note that unlike StringBuffer, the string version returned is independent of the string builder.
- Returns:
The builder as a String.
- public StringBuffer toStringBuffer()[source]
Gets a StringBuffer version of the string builder, creating a new instance each time the method is called.
- Returns:
The builder as a StringBuffer.
- public StringBuilder toStringBuilder()[source]
Gets a StringBuilder version of the string builder, creating a new instance each time the method is called.
- Returns:
The builder as a StringBuilder.
- Since:
3.2
- public StrBuilder trim()[source]
Trims the builder by removing characters less than or equal to a space from the beginning and end.
- Returns:
thisinstance.
- protected void validateIndex(int index)[source]
Validates parameters defining a single index in the builder.
- Parameters:
index – The index, must be valid.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.
- protected int validateRange(int startIndex, int endIndex)[source]
Validates parameters defining a range of the builder.
- Parameters:
startIndex – The start index, inclusive, must be valid.
endIndex – The end index, exclusive, must be valid except that if too large it is treated as end of string.
- Returns:
The new string.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is invalid.