@Deprecated public class StrBuilder extends java.lang.Object implements java.lang.CharSequence, java.lang.Appendable, java.io.Serializable, Builder<java.lang.String>
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)
.
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.
Constructor and Description |
---|
StrBuilder()
Deprecated.
Constructor that creates an empty builder initial capacity 32 characters.
|
StrBuilder(int initialCapacity)
Deprecated.
Constructor that creates an empty builder the specified initial capacity.
|
StrBuilder(java.lang.String str)
Deprecated.
Constructor that creates a builder from the string, allocating
32 extra characters for growth.
|
Modifier and Type | Method and Description |
---|---|
StrBuilder |
append(boolean value)
Deprecated.
Appends a boolean value to the string builder.
|
StrBuilder |
append(char ch)
Deprecated.
Appends a char value to the string builder.
|
StrBuilder |
append(char[] chars)
Deprecated.
Appends a char array to the string builder.
|
StrBuilder |
append(char[] chars,
int startIndex,
int length)
Deprecated.
Appends a char array to the string builder.
|
StrBuilder |
append(java.nio.CharBuffer buf)
Deprecated.
Appends the contents of a char buffer to this string builder.
|
StrBuilder |
append(java.nio.CharBuffer buf,
int startIndex,
int length)
Deprecated.
Appends the contents of a char buffer to this string builder.
|
StrBuilder |
append(java.lang.CharSequence seq)
Deprecated.
Appends a CharSequence to this string builder.
|
StrBuilder |
append(java.lang.CharSequence seq,
int startIndex,
int length)
Deprecated.
Appends part of a CharSequence to this string builder.
|
StrBuilder |
append(double value)
Deprecated.
Appends a double value to the string builder using
String.valueOf . |
StrBuilder |
append(float value)
Deprecated.
Appends a float value to the string builder using
String.valueOf . |
StrBuilder |
append(int value)
Deprecated.
Appends an int value to the string builder using
String.valueOf . |
StrBuilder |
append(long value)
Deprecated.
Appends a long value to the string builder using
String.valueOf . |
StrBuilder |
append(java.lang.Object obj)
Deprecated.
Appends an object to this string builder.
|
StrBuilder |
append(StrBuilder str)
Deprecated.
Appends another string builder to this string builder.
|
StrBuilder |
append(StrBuilder str,
int startIndex,
int length)
Deprecated.
Appends part of a string builder to this string builder.
|
StrBuilder |
append(java.lang.String str)
Deprecated.
Appends a string to this string builder.
|
StrBuilder |
append(java.lang.StringBuffer str)
Deprecated.
Appends a string buffer to this string builder.
|
StrBuilder |
append(java.lang.StringBuffer str,
int startIndex,
int length)
Deprecated.
Appends part of a string buffer to this string builder.
|
StrBuilder |
append(java.lang.StringBuilder str)
Deprecated.
Appends a StringBuilder to this string builder.
|
StrBuilder |
append(java.lang.StringBuilder str,
int startIndex,
int length)
Deprecated.
Appends part of a StringBuilder to this string builder.
|
StrBuilder |
append(java.lang.String str,
int startIndex,
int length)
Deprecated.
Appends part of a string to this string builder.
|
StrBuilder |
append(java.lang.String format,
java.lang.Object... objs)
Deprecated.
Calls
String.format(String, Object...) and appends the result. |
StrBuilder |
appendAll(java.lang.Iterable<?> iterable)
Deprecated.
Appends each item in an iterable to the builder without any separators.
|
StrBuilder |
appendAll(java.util.Iterator<?> it)
Deprecated.
Appends each item in an iterator to the builder without any separators.
|
<T> StrBuilder |
appendAll(T... array)
Deprecated.
Appends each item in an array to the builder without any separators.
|
StrBuilder |
appendFixedWidthPadLeft(int value,
int width,
char padChar)
Deprecated.
Appends an object to the builder padding on the left to a fixed width.
|
StrBuilder |
appendFixedWidthPadLeft(java.lang.Object obj,
int width,
char padChar)
Deprecated.
Appends an object to the builder padding on the left to a fixed width.
|
StrBuilder |
appendFixedWidthPadRight(int value,
int width,
char padChar)
Deprecated.
Appends an object to the builder padding on the right to a fixed length.
|
StrBuilder |
appendFixedWidthPadRight(java.lang.Object obj,
int width,
char padChar)
Deprecated.
Appends an object to the builder padding on the right to a fixed length.
|
StrBuilder |
appendln(boolean value)
Deprecated.
Appends a boolean value followed by a new line to the string builder.
|
StrBuilder |
appendln(char ch)
Deprecated.
Appends a char value followed by a new line to the string builder.
|
StrBuilder |
appendln(char[] chars)
Deprecated.
Appends a char array followed by a new line to the string builder.
|
StrBuilder |
appendln(char[] chars,
int startIndex,
int length)
Deprecated.
Appends a char array followed by a new line to the string builder.
|
StrBuilder |
appendln(double value)
Deprecated.
Appends a double value followed by a new line to the string builder using
String.valueOf . |
StrBuilder |
appendln(float value)
Deprecated.
Appends a float value followed by a new line to the string builder using
String.valueOf . |
StrBuilder |
appendln(int value)
Deprecated.
Appends an int value followed by a new line to the string builder using
String.valueOf . |
StrBuilder |
appendln(long value)
Deprecated.
Appends a long value followed by a new line to the string builder using
String.valueOf . |
StrBuilder |
appendln(java.lang.Object obj)
Deprecated.
Appends an object followed by a new line to this string builder.
|
StrBuilder |
appendln(StrBuilder str)
Deprecated.
Appends another string builder followed by a new line to this string builder.
|
StrBuilder |
appendln(StrBuilder str,
int startIndex,
int length)
Deprecated.
Appends part of a string builder followed by a new line to this string builder.
|
StrBuilder |
appendln(java.lang.String str)
Deprecated.
Appends a string followed by a new line to this string builder.
|
StrBuilder |
appendln(java.lang.StringBuffer str)
Deprecated.
Appends a string buffer followed by a new line to this string builder.
|
StrBuilder |
appendln(java.lang.StringBuffer str,
int startIndex,
int length)
Deprecated.
Appends part of a string buffer followed by a new line to this string builder.
|
StrBuilder |
appendln(java.lang.StringBuilder str)
Deprecated.
Appends a string builder followed by a new line to this string builder.
|
StrBuilder |
appendln(java.lang.StringBuilder str,
int startIndex,
int length)
Deprecated.
Appends part of a string builder followed by a new line to this string builder.
|
StrBuilder |
appendln(java.lang.String str,
int startIndex,
int length)
Deprecated.
Appends part of a string followed by a new line to this string builder.
|
StrBuilder |
appendln(java.lang.String format,
java.lang.Object... objs)
Deprecated.
Calls
String.format(String, Object...) and appends the result. |
StrBuilder |
appendNewLine()
Deprecated.
Appends the new line string to this string builder.
|
StrBuilder |
appendNull()
Deprecated.
Appends the text representing
null to this string builder. |
StrBuilder |
appendPadding(int length,
char padChar)
Deprecated.
Appends the pad character to the builder the specified number of times.
|
StrBuilder |
appendSeparator(char separator)
Deprecated.
Appends a separator if the builder is currently non-empty.
|
StrBuilder |
appendSeparator(char standard,
char defaultIfEmpty)
Deprecated.
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) . |
StrBuilder |
appendSeparator(char separator,
int loopIndex)
Deprecated.
Appends a separator to the builder if the loop index is greater than zero.
|
StrBuilder |
appendSeparator(java.lang.String separator)
Deprecated.
Appends a separator if the builder is currently non-empty.
|
StrBuilder |
appendSeparator(java.lang.String separator,
int loopIndex)
Deprecated.
Appends a separator to the builder if the loop index is greater than zero.
|
StrBuilder |
appendSeparator(java.lang.String standard,
java.lang.String defaultIfEmpty)
Deprecated.
Appends one of both separators to the StrBuilder.
|
void |
appendTo(java.lang.Appendable appendable)
Deprecated.
Appends current contents of this
StrBuilder to the
provided Appendable . |
StrBuilder |
appendWithSeparators(java.lang.Iterable<?> iterable,
java.lang.String separator)
Deprecated.
Appends an iterable placing separators between each value, but
not before the first or after the last.
|
StrBuilder |
appendWithSeparators(java.util.Iterator<?> it,
java.lang.String separator)
Deprecated.
Appends an iterator placing separators between each value, but
not before the first or after the last.
|
StrBuilder |
appendWithSeparators(java.lang.Object[] array,
java.lang.String separator)
Deprecated.
Appends an array placing separators between each value, but
not before the first or after the last.
|
java.io.Reader |
asReader()
Deprecated.
Gets the contents of this builder as a Reader.
|
StrTokenizer |
asTokenizer()
Deprecated.
Creates a tokenizer that can tokenize the contents of this builder.
|
java.io.Writer |
asWriter()
Deprecated.
Gets this builder as a Writer that can be written to.
|
java.lang.String |
build()
Deprecated.
Implement the
Builder interface. |
int |
capacity()
Deprecated.
Gets the current size of the internal character array buffer.
|
char |
charAt(int index)
Deprecated.
Gets the character at the specified index.
|
StrBuilder |
clear()
Deprecated.
Clears the string builder (convenience Collections API style method).
|
boolean |
contains(char ch)
Deprecated.
Checks if the string builder contains the specified char.
|
boolean |
contains(java.lang.String str)
Deprecated.
Checks if the string builder contains the specified string.
|
boolean |
contains(StrMatcher matcher)
Deprecated.
Checks if the string builder contains a string matched using the
specified matcher.
|
StrBuilder |
delete(int startIndex,
int endIndex)
Deprecated.
Deletes the characters between the two specified indices.
|
StrBuilder |
deleteAll(char ch)
Deprecated.
Deletes the character wherever it occurs in the builder.
|
StrBuilder |
deleteAll(java.lang.String str)
Deprecated.
Deletes the string wherever it occurs in the builder.
|
StrBuilder |
deleteAll(StrMatcher matcher)
Deprecated.
Deletes all parts of the builder that the matcher matches.
|
StrBuilder |
deleteCharAt(int index)
Deprecated.
Deletes the character at the specified index.
|
StrBuilder |
deleteFirst(char ch)
Deprecated.
Deletes the character wherever it occurs in the builder.
|
StrBuilder |
deleteFirst(java.lang.String str)
Deprecated.
Deletes the string wherever it occurs in the builder.
|
StrBuilder |
deleteFirst(StrMatcher matcher)
Deprecated.
Deletes the first match within the builder using the specified matcher.
|
boolean |
endsWith(java.lang.String str)
Deprecated.
Checks whether this builder ends with the specified string.
|
StrBuilder |
ensureCapacity(int capacity)
Deprecated.
Checks the capacity and ensures that it is at least the size specified.
|
boolean |
equals(java.lang.Object obj)
Deprecated.
Checks the contents of this builder against another to see if they
contain the same character content.
|
boolean |
equals(StrBuilder other)
Deprecated.
Checks the contents of this builder against another to see if they
contain the same character content.
|
boolean |
equalsIgnoreCase(StrBuilder other)
Deprecated.
Checks the contents of this builder against another to see if they
contain the same character content ignoring case.
|
char[] |
getChars(char[] destination)
Deprecated.
Copies the character array into the specified array.
|
void |
getChars(int startIndex,
int endIndex,
char[] destination,
int destinationIndex)
Deprecated.
Copies the character array into the specified array.
|
java.lang.String |
getNewLineText()
Deprecated.
Gets the text to be appended when a new line is added.
|
java.lang.String |
getNullText()
Deprecated.
Gets the text to be appended when null is added.
|
int |
hashCode()
Deprecated.
Gets a suitable hash code for this builder.
|
int |
indexOf(char ch)
Deprecated.
Searches the string builder to find the first reference to the specified char.
|
int |
indexOf(char ch,
int startIndex)
Deprecated.
Searches the string builder to find the first reference to the specified char.
|
int |
indexOf(java.lang.String str)
Deprecated.
Searches the string builder to find the first reference to the specified string.
|
int |
indexOf(java.lang.String str,
int startIndex)
Deprecated.
Searches the string builder to find the first reference to the specified
string starting searching from the given index.
|
int |
indexOf(StrMatcher matcher)
Deprecated.
Searches the string builder using the matcher to find the first match.
|
int |
indexOf(StrMatcher matcher,
int startIndex)
Deprecated.
Searches the string builder using the matcher to find the first
match searching from the given index.
|
StrBuilder |
insert(int index,
boolean value)
Deprecated.
Inserts the value into this builder.
|
StrBuilder |
insert(int index,
char value)
Deprecated.
Inserts the value into this builder.
|
StrBuilder |
insert(int index,
char[] chars)
Deprecated.
Inserts the character array into this builder.
|
StrBuilder |
insert(int index,
char[] chars,
int offset,
int length)
Deprecated.
Inserts part of the character array into this builder.
|
StrBuilder |
insert(int index,
double value)
Deprecated.
Inserts the value into this builder.
|
StrBuilder |
insert(int index,
float value)
Deprecated.
Inserts the value into this builder.
|
StrBuilder |
insert(int index,
int value)
Deprecated.
Inserts the value into this builder.
|
StrBuilder |
insert(int index,
long value)
Deprecated.
Inserts the value into this builder.
|
StrBuilder |
insert(int index,
java.lang.Object obj)
Deprecated.
Inserts the string representation of an object into this builder.
|
StrBuilder |
insert(int index,
java.lang.String str)
Deprecated.
Inserts the string into this builder.
|
boolean |
isEmpty()
Deprecated.
Checks is the string builder is empty (convenience Collections API style method).
|
int |
lastIndexOf(char ch)
Deprecated.
Searches the string builder to find the last reference to the specified char.
|
int |
lastIndexOf(char ch,
int startIndex)
Deprecated.
Searches the string builder to find the last reference to the specified char.
|
int |
lastIndexOf(java.lang.String str)
Deprecated.
Searches the string builder to find the last reference to the specified string.
|
int |
lastIndexOf(java.lang.String str,
int startIndex)
Deprecated.
Searches the string builder to find the last reference to the specified
string starting searching from the given index.
|
int |
lastIndexOf(StrMatcher matcher)
Deprecated.
Searches the string builder using the matcher to find the last match.
|
int |
lastIndexOf(StrMatcher matcher,
int startIndex)
Deprecated.
Searches the string builder using the matcher to find the last
match searching from the given index.
|
java.lang.String |
leftString(int length)
Deprecated.
Extracts the leftmost characters from the string builder without
throwing an exception.
|
int |
length()
Deprecated.
Gets the length of the string builder.
|
java.lang.String |
midString(int index,
int length)
Deprecated.
Extracts some characters from the middle of the string builder without
throwing an exception.
|
StrBuilder |
minimizeCapacity()
Deprecated.
Minimizes the capacity to the actual length of the string.
|
int |
readFrom(java.lang.Readable readable)
Deprecated.
If possible, reads chars from the provided
Readable directly into underlying
character buffer without making extra copies. |
StrBuilder |
replace(int startIndex,
int endIndex,
java.lang.String replaceStr)
Deprecated.
Replaces a portion of the string builder with another string.
|
StrBuilder |
replace(StrMatcher matcher,
java.lang.String replaceStr,
int startIndex,
int endIndex,
int replaceCount)
Deprecated.
Advanced search and replaces within the builder using a matcher.
|
StrBuilder |
replaceAll(char search,
char replace)
Deprecated.
Replaces the search character with the replace character
throughout the builder.
|
StrBuilder |
replaceAll(java.lang.String searchStr,
java.lang.String replaceStr)
Deprecated.
Replaces the search string with the replace string throughout the builder.
|
StrBuilder |
replaceAll(StrMatcher matcher,
java.lang.String replaceStr)
Deprecated.
Replaces all matches within the builder with the replace string.
|
StrBuilder |
replaceFirst(char search,
char replace)
Deprecated.
Replaces the first instance of the search character with the
replace character in the builder.
|
StrBuilder |
replaceFirst(java.lang.String searchStr,
java.lang.String replaceStr)
Deprecated.
Replaces the first instance of the search string with the replace string.
|
StrBuilder |
replaceFirst(StrMatcher matcher,
java.lang.String replaceStr)
Deprecated.
Replaces the first match within the builder with the replace string.
|
StrBuilder |
reverse()
Deprecated.
Reverses the string builder placing each character in the opposite index.
|
java.lang.String |
rightString(int length)
Deprecated.
Extracts the rightmost characters from the string builder without
throwing an exception.
|
StrBuilder |
setCharAt(int index,
char ch)
Deprecated.
Sets the character at the specified index.
|
StrBuilder |
setLength(int length)
Deprecated.
Updates the length of the builder by either dropping the last characters
or adding filler of Unicode zero.
|
StrBuilder |
setNewLineText(java.lang.String newLine)
Deprecated.
Sets the text to be appended when a new line is added.
|
StrBuilder |
setNullText(java.lang.String nullText)
Deprecated.
Sets the text to be appended when null is added.
|
int |
size()
Deprecated.
Gets the length of the string builder.
|
boolean |
startsWith(java.lang.String str)
Deprecated.
Checks whether this builder starts with the specified string.
|
java.lang.CharSequence |
subSequence(int startIndex,
int endIndex)
Deprecated.
|
java.lang.String |
substring(int start)
Deprecated.
Extracts a portion of this string builder as a string.
|
java.lang.String |
substring(int startIndex,
int endIndex)
Deprecated.
Extracts a portion of this string builder as a string.
|
char[] |
toCharArray()
Deprecated.
Copies the builder's character array into a new character array.
|
char[] |
toCharArray(int startIndex,
int endIndex)
Deprecated.
Copies part of the builder's character array into a new character array.
|
java.lang.String |
toString()
Deprecated.
Gets a String version of the string builder, creating a new instance
each time the method is called.
|
java.lang.StringBuffer |
toStringBuffer()
Deprecated.
Gets a StringBuffer version of the string builder, creating a
new instance each time the method is called.
|
java.lang.StringBuilder |
toStringBuilder()
Deprecated.
Gets a StringBuilder version of the string builder, creating a
new instance each time the method is called.
|
StrBuilder |
trim()
Deprecated.
Trims the builder by removing characters less than or equal to a space
from the beginning and end.
|
public StrBuilder()
public StrBuilder(int initialCapacity)
initialCapacity
- the initial capacity, zero or less will be converted to 32public StrBuilder(java.lang.String str)
str
- the string to copy, null treated as blank stringpublic java.lang.String getNewLineText()
public StrBuilder setNewLineText(java.lang.String newLine)
newLine
- the new line text, null means use system defaultpublic java.lang.String getNullText()
public StrBuilder setNullText(java.lang.String nullText)
nullText
- the null text, null means no appendpublic int length()
length
in interface java.lang.CharSequence
public StrBuilder setLength(int length)
length
- the length to set to, must be zero or positivejava.lang.IndexOutOfBoundsException
- if the length is negativepublic int capacity()
public StrBuilder ensureCapacity(int capacity)
capacity
- the capacity to ensurepublic StrBuilder minimizeCapacity()
public int size()
This method is the same as length()
and is provided to match the
API of Collections.
public boolean isEmpty()
This method is the same as checking length()
and is provided to match the
API of Collections.
true
if the size is 0
.public StrBuilder clear()
This method does not reduce the size of the internal character buffer.
To do that, call clear()
followed by minimizeCapacity()
.
This method is the same as setLength(int)
called with zero
and is provided to match the API of Collections.
public char charAt(int index)
charAt
in interface java.lang.CharSequence
index
- the index to retrieve, must be validjava.lang.IndexOutOfBoundsException
- if the index is invalidsetCharAt(int, char)
,
deleteCharAt(int)
public StrBuilder setCharAt(int index, char ch)
index
- the index to setch
- the new characterjava.lang.IndexOutOfBoundsException
- if the index is invalidcharAt(int)
,
deleteCharAt(int)
public StrBuilder deleteCharAt(int index)
index
- the index to deletejava.lang.IndexOutOfBoundsException
- if the index is invalidcharAt(int)
,
setCharAt(int, char)
public char[] toCharArray()
public char[] toCharArray(int startIndex, int endIndex)
startIndex
- the start index, inclusive, must be validendIndex
- the end index, exclusive, must be valid except that
if too large it is treated as end of stringjava.lang.IndexOutOfBoundsException
- if startIndex is invalid,
or if endIndex is invalid (but endIndex greater than size is valid)public char[] getChars(char[] destination)
destination
- the destination array, null will cause an array to be createdpublic void getChars(int startIndex, int endIndex, char[] destination, int destinationIndex)
startIndex
- first index to copy, inclusive, must be validendIndex
- last index, exclusive, must be validdestination
- the destination array, must not be null or too smalldestinationIndex
- the index to start copying in destinationjava.lang.NullPointerException
- if the array is nulljava.lang.IndexOutOfBoundsException
- if any index is invalidpublic int readFrom(java.lang.Readable readable) throws java.io.IOException
Readable
directly into underlying
character buffer without making extra copies.readable
- object to read fromjava.io.IOException
- if an I/O error occursappendTo(Appendable)
public StrBuilder appendNewLine()
The new line string can be altered using setNewLineText(String)
.
This might be used to force the output to always use Unix line endings
even when on Windows.
public StrBuilder appendNull()
null
to this string builder.public StrBuilder append(java.lang.Object obj)
appendNull()
.obj
- the object to appendpublic StrBuilder append(java.lang.CharSequence seq)
appendNull()
.append
in interface java.lang.Appendable
seq
- the CharSequence to appendpublic StrBuilder append(java.lang.CharSequence seq, int startIndex, int length)
appendNull()
.append
in interface java.lang.Appendable
seq
- the CharSequence to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder append(java.lang.String str)
appendNull()
.str
- the string to appendpublic StrBuilder append(java.lang.String str, int startIndex, int length)
appendNull()
.str
- the string to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder append(java.lang.String format, java.lang.Object... objs)
String.format(String, Object...)
and appends the result.format
- the format stringobjs
- the objects to use in the format stringthis
to enable chainingString.format(String, Object...)
public StrBuilder append(java.nio.CharBuffer buf)
appendNull()
.buf
- the char buffer to appendpublic StrBuilder append(java.nio.CharBuffer buf, int startIndex, int length)
appendNull()
.buf
- the char buffer to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder append(java.lang.StringBuffer str)
appendNull()
.str
- the string buffer to appendpublic StrBuilder append(java.lang.StringBuffer str, int startIndex, int length)
appendNull()
.str
- the string to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder append(java.lang.StringBuilder str)
appendNull()
.str
- the StringBuilder to appendpublic StrBuilder append(java.lang.StringBuilder str, int startIndex, int length)
appendNull()
.str
- the StringBuilder to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder append(StrBuilder str)
appendNull()
.str
- the string builder to appendpublic StrBuilder append(StrBuilder str, int startIndex, int length)
appendNull()
.str
- the string to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder append(char[] chars)
appendNull()
.chars
- the char array to appendpublic StrBuilder append(char[] chars, int startIndex, int length)
appendNull()
.chars
- the char array to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder append(boolean value)
value
- the value to appendpublic StrBuilder append(char ch)
append
in interface java.lang.Appendable
ch
- the value to appendpublic StrBuilder append(int value)
String.valueOf
.value
- the value to appendpublic StrBuilder append(long value)
String.valueOf
.value
- the value to appendpublic StrBuilder append(float value)
String.valueOf
.value
- the value to appendpublic StrBuilder append(double value)
String.valueOf
.value
- the value to appendpublic StrBuilder appendln(java.lang.Object obj)
appendNull()
.obj
- the object to appendpublic StrBuilder appendln(java.lang.String str)
appendNull()
.str
- the string to appendpublic StrBuilder appendln(java.lang.String str, int startIndex, int length)
appendNull()
.str
- the string to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder appendln(java.lang.String format, java.lang.Object... objs)
String.format(String, Object...)
and appends the result.format
- the format stringobjs
- the objects to use in the format stringthis
to enable chainingString.format(String, Object...)
public StrBuilder appendln(java.lang.StringBuffer str)
appendNull()
.str
- the string buffer to appendpublic StrBuilder appendln(java.lang.StringBuilder str)
appendNull()
.str
- the string builder to appendpublic StrBuilder appendln(java.lang.StringBuilder str, int startIndex, int length)
appendNull()
.str
- the string builder to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder appendln(java.lang.StringBuffer str, int startIndex, int length)
appendNull()
.str
- the string to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder appendln(StrBuilder str)
appendNull()
.str
- the string builder to appendpublic StrBuilder appendln(StrBuilder str, int startIndex, int length)
appendNull()
.str
- the string to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder appendln(char[] chars)
appendNull()
.chars
- the char array to appendpublic StrBuilder appendln(char[] chars, int startIndex, int length)
appendNull()
.chars
- the char array to appendstartIndex
- the start index, inclusive, must be validlength
- the length to append, must be validpublic StrBuilder appendln(boolean value)
value
- the value to appendpublic StrBuilder appendln(char ch)
ch
- the value to appendpublic StrBuilder appendln(int value)
String.valueOf
.value
- the value to appendpublic StrBuilder appendln(long value)
String.valueOf
.value
- the value to appendpublic StrBuilder appendln(float value)
String.valueOf
.value
- the value to appendpublic StrBuilder appendln(double value)
String.valueOf
.value
- the value to appendpublic <T> StrBuilder appendAll(T... array)
append(Object)
.T
- the element typearray
- the array to appendpublic StrBuilder appendAll(java.lang.Iterable<?> iterable)
append(Object)
.iterable
- the iterable to appendpublic StrBuilder appendAll(java.util.Iterator<?> it)
append(Object)
.it
- the iterator to appendpublic StrBuilder appendWithSeparators(java.lang.Object[] array, java.lang.String separator)
append(Object)
.array
- the array to appendseparator
- the separator to use, null means no separatorpublic StrBuilder appendWithSeparators(java.lang.Iterable<?> iterable, java.lang.String separator)
append(Object)
.iterable
- the iterable to appendseparator
- the separator to use, null means no separatorpublic StrBuilder appendWithSeparators(java.util.Iterator<?> it, java.lang.String separator)
append(Object)
.it
- the iterator to appendseparator
- the separator to use, null means no separatorpublic StrBuilder appendSeparator(java.lang.String separator)
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)
.separator
- the separator to use, null means no separatorpublic StrBuilder appendSeparator(java.lang.String standard, java.lang.String defaultIfEmpty)
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)
standard
- the separator if builder is not empty, null means no separatordefaultIfEmpty
- the separator if builder is empty, null means no separatorpublic StrBuilder appendSeparator(char separator)
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)
.separator
- the separator to usepublic StrBuilder appendSeparator(char standard, char defaultIfEmpty)
append(char)
.standard
- the separator if builder is not emptydefaultIfEmpty
- the separator if builder is emptypublic StrBuilder appendSeparator(java.lang.String separator, int loopIndex)
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)
.separator
- the separator to use, null means no separatorloopIndex
- the loop indexpublic StrBuilder appendSeparator(char separator, int loopIndex)
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)
.separator
- the separator to useloopIndex
- the loop indexpublic StrBuilder appendPadding(int length, char padChar)
length
- the length to append, negative means no appendpadChar
- the character to appendpublic StrBuilder appendFixedWidthPadLeft(java.lang.Object obj, int width, char padChar)
toString
of 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.obj
- the object to append, null uses null textwidth
- the fixed field width, zero or negative has no effectpadChar
- the pad character to usepublic StrBuilder appendFixedWidthPadLeft(int value, int width, char padChar)
String.valueOf
of the int
value is used.
If the formatted value is larger than the length, the left hand side is lost.value
- the value to appendwidth
- the fixed field width, zero or negative has no effectpadChar
- the pad character to usepublic StrBuilder appendFixedWidthPadRight(java.lang.Object obj, int width, char padChar)
toString
of 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.obj
- the object to append, null uses null textwidth
- the fixed field width, zero or negative has no effectpadChar
- the pad character to usepublic StrBuilder appendFixedWidthPadRight(int value, int width, char padChar)
String.valueOf
of the int
value is used.
If the object is larger than the length, the right hand side is lost.value
- the value to appendwidth
- the fixed field width, zero or negative has no effectpadChar
- the pad character to usepublic StrBuilder insert(int index, java.lang.Object obj)
index
- the index to add at, must be validobj
- the object to insertjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder insert(int index, java.lang.String str)
index
- the index to add at, must be validstr
- the string to insertjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder insert(int index, char[] chars)
index
- the index to add at, must be validchars
- the char array to insertjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder insert(int index, char[] chars, int offset, int length)
index
- the index to add at, must be validchars
- the char array to insertoffset
- the offset into the character array to start at, must be validlength
- the length of the character array part to copy, must be positivejava.lang.IndexOutOfBoundsException
- if any index is invalidpublic StrBuilder insert(int index, boolean value)
index
- the index to add at, must be validvalue
- the value to insertjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder insert(int index, char value)
index
- the index to add at, must be validvalue
- the value to insertjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder insert(int index, int value)
index
- the index to add at, must be validvalue
- the value to insertjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder insert(int index, long value)
index
- the index to add at, must be validvalue
- the value to insertjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder insert(int index, float value)
index
- the index to add at, must be validvalue
- the value to insertjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder insert(int index, double value)
index
- the index to add at, must be validvalue
- the value to insertjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder delete(int startIndex, int endIndex)
startIndex
- the start index, inclusive, must be validendIndex
- the end index, exclusive, must be valid except
that if too large it is treated as end of stringjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder deleteAll(char ch)
ch
- the character to deletepublic StrBuilder deleteFirst(char ch)
ch
- the character to deletepublic StrBuilder deleteAll(java.lang.String str)
str
- the string to delete, null causes no actionpublic StrBuilder deleteFirst(java.lang.String str)
str
- the string to delete, null causes no actionpublic StrBuilder deleteAll(StrMatcher matcher)
Matchers can be used to perform advanced deletion behaviour. For example you could write a matcher to delete all occurrences where the character 'a' is followed by a number.
matcher
- the matcher to use to find the deletion, null causes no actionpublic StrBuilder deleteFirst(StrMatcher matcher)
Matchers can be used to perform advanced deletion behaviour. For example you could write a matcher to delete where the character 'a' is followed by a number.
matcher
- the matcher to use to find the deletion, null causes no actionpublic StrBuilder replace(int startIndex, int endIndex, java.lang.String replaceStr)
startIndex
- the start index, inclusive, must be validendIndex
- the end index, exclusive, must be valid except
that if too large it is treated as end of stringreplaceStr
- the string to replace with, null means delete rangejava.lang.IndexOutOfBoundsException
- if the index is invalidpublic StrBuilder replaceAll(char search, char replace)
search
- the search characterreplace
- the replace characterpublic StrBuilder replaceFirst(char search, char replace)
search
- the search characterreplace
- the replace characterpublic StrBuilder replaceAll(java.lang.String searchStr, java.lang.String replaceStr)
searchStr
- the search string, null causes no action to occurreplaceStr
- the replace string, null is equivalent to an empty stringpublic StrBuilder replaceFirst(java.lang.String searchStr, java.lang.String replaceStr)
searchStr
- the search string, null causes no action to occurreplaceStr
- the replace string, null is equivalent to an empty stringpublic StrBuilder replaceAll(StrMatcher matcher, java.lang.String replaceStr)
Matchers can be used to perform advanced replace behaviour. For example you could write a matcher to replace all occurrences where the character 'a' is followed by a number.
matcher
- the matcher to use to find the deletion, null causes no actionreplaceStr
- the replace string, null is equivalent to an empty stringpublic StrBuilder replaceFirst(StrMatcher matcher, java.lang.String replaceStr)
Matchers can be used to perform advanced replace behaviour. For example you could write a matcher to replace where the character 'a' is followed by a number.
matcher
- the matcher to use to find the deletion, null causes no actionreplaceStr
- the replace string, null is equivalent to an empty stringpublic StrBuilder replace(StrMatcher matcher, java.lang.String replaceStr, int startIndex, int endIndex, int replaceCount)
Matchers can be used to perform advanced behaviour. For example you could write a matcher to delete all occurrences where the character 'a' is followed by a number.
matcher
- the matcher to use to find the deletion, null causes no actionreplaceStr
- the string to replace the match with, null is a deletestartIndex
- the start index, inclusive, must be validendIndex
- the end index, exclusive, must be valid except
that if too large it is treated as end of stringreplaceCount
- the number of times to replace, -1 for replace alljava.lang.IndexOutOfBoundsException
- if start index is invalidpublic StrBuilder reverse()
public StrBuilder trim()
public boolean startsWith(java.lang.String str)
Note that this method handles null input quietly, unlike String.
str
- the string to search for, null returns falsepublic boolean endsWith(java.lang.String str)
Note that this method handles null input quietly, unlike String.
str
- the string to search for, null returns falsepublic java.lang.CharSequence subSequence(int startIndex, int endIndex)
subSequence
in interface java.lang.CharSequence
public java.lang.String substring(int start)
start
- the start index, inclusive, must be validjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic java.lang.String substring(int startIndex, int endIndex)
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.
startIndex
- the start index, inclusive, must be validendIndex
- the end index, exclusive, must be valid except
that if too large it is treated as end of stringjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic java.lang.String leftString(int length)
This method extracts the left length
characters 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.
length
- the number of characters to extract, negative returns empty stringpublic java.lang.String rightString(int length)
This method extracts the right length
characters 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.
length
- the number of characters to extract, negative returns empty stringpublic java.lang.String midString(int index, int length)
This method extracts length
characters 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.
index
- the index to start at, negative means zerolength
- the number of characters to extract, negative returns empty stringpublic boolean contains(char ch)
ch
- the character to findpublic boolean contains(java.lang.String str)
str
- the string to findpublic boolean contains(StrMatcher matcher)
Matchers can be used to perform advanced searching behaviour. For example you could write a matcher to search for the character 'a' followed by a number.
matcher
- the matcher to use, null returns -1public int indexOf(char ch)
ch
- the character to findpublic int indexOf(char ch, int startIndex)
ch
- the character to findstartIndex
- the index to start at, invalid index rounded to edgepublic int indexOf(java.lang.String str)
Note that a null input string will return -1, whereas the JDK throws an exception.
str
- the string to find, null returns -1public int indexOf(java.lang.String str, int startIndex)
Note that a null input string will return -1, whereas the JDK throws an exception.
str
- the string to find, null returns -1startIndex
- the index to start at, invalid index rounded to edgepublic int indexOf(StrMatcher matcher)
Matchers can be used to perform advanced searching behaviour. For example you could write a matcher to find the character 'a' followed by a number.
matcher
- the matcher to use, null returns -1public int indexOf(StrMatcher matcher, int startIndex)
Matchers can be used to perform advanced searching behaviour. For example you could write a matcher to find the character 'a' followed by a number.
matcher
- the matcher to use, null returns -1startIndex
- the index to start at, invalid index rounded to edgepublic int lastIndexOf(char ch)
ch
- the character to findpublic int lastIndexOf(char ch, int startIndex)
ch
- the character to findstartIndex
- the index to start at, invalid index rounded to edgepublic int lastIndexOf(java.lang.String str)
Note that a null input string will return -1, whereas the JDK throws an exception.
str
- the string to find, null returns -1public int lastIndexOf(java.lang.String str, int startIndex)
Note that a null input string will return -1, whereas the JDK throws an exception.
str
- the string to find, null returns -1startIndex
- the index to start at, invalid index rounded to edgepublic int lastIndexOf(StrMatcher matcher)
Matchers can be used to perform advanced searching behaviour. For example you could write a matcher to find the character 'a' followed by a number.
matcher
- the matcher to use, null returns -1public int lastIndexOf(StrMatcher matcher, int startIndex)
Matchers can be used to perform advanced searching behaviour. For example you could write a matcher to find the character 'a' followed by a number.
matcher
- the matcher to use, null returns -1startIndex
- the index to start at, invalid index rounded to edgepublic StrTokenizer asTokenizer()
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 reset
to 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,dIn 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)
or StrTokenizer.reset(char[])
with a non-null value will break the link with the builder.
public java.io.Reader asReader()
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, call asReader
, 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.
public java.io.Writer asWriter()
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
,
call asWriter
, and populate away. The data is available
at any time using the methods of the StrBuilder
.
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.
public void appendTo(java.lang.Appendable appendable) throws java.io.IOException
StrBuilder
to the
provided Appendable
.
This method tries to avoid doing any extra copies of contents.
appendable
- the appendable to append data tojava.io.IOException
- if an I/O error occursreadFrom(Readable)
public boolean equalsIgnoreCase(StrBuilder other)
other
- the object to check, null returns falsepublic boolean equals(StrBuilder other)
other
- the object to check, null returns falsepublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the object to check, null returns falsepublic int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
Note that unlike StringBuffer, the string version returned is independent of the string builder.
toString
in interface java.lang.CharSequence
toString
in class java.lang.Object
public java.lang.StringBuffer toStringBuffer()
public java.lang.StringBuilder toStringBuilder()
public java.lang.String build()
Builder
interface.build
in interface Builder<java.lang.String>
toString()
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"