Package com.badlogic.gdx.utils
Class StringBuilder
- java.lang.Object
-
- com.badlogic.gdx.utils.StringBuilder
-
- All Implemented Interfaces:
java.lang.Appendable
,java.lang.CharSequence
public class StringBuilder extends java.lang.Object implements java.lang.Appendable, java.lang.CharSequence
AStringBuilder
that implements equals and hashcode.- See Also:
CharSequence
,Appendable
,StringBuilder
,String
-
-
Constructor Summary
Constructors Constructor Description StringBuilder()
Constructs an instance with an initial capacity of16
.StringBuilder(int capacity)
Constructs an instance with the specified capacity.StringBuilder(StringBuilder builder)
StringBuilder(java.lang.CharSequence seq)
Constructs an instance that's initialized with the contents of the specifiedCharSequence
.StringBuilder(java.lang.String string)
Constructs an instance that's initialized with the contents of the specifiedString
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringBuilder
append(boolean b)
Appends the string representation of the specifiedboolean
value.StringBuilder
append(char c)
Appends the string representation of the specifiedchar
value.StringBuilder
append(char[] ch)
Appends the string representation of the specifiedchar[]
.StringBuilder
append(char[] str, int offset, int len)
Appends the string representation of the specified subset of thechar[]
.StringBuilder
append(double d)
Appends the string representation of the specifieddouble
value.StringBuilder
append(float f)
Appends the string representation of the specifiedfloat
value.StringBuilder
append(int value)
Appends the string representation of the specifiedint
value.StringBuilder
append(int value, int minLength)
Appends the string representation of the specifiedint
value.StringBuilder
append(int value, int minLength, char prefix)
Appends the string representation of the specifiedint
value.StringBuilder
append(long value)
Appends the string representation of the specifiedlong
value.StringBuilder
append(long value, int minLength)
Appends the string representation of the specifiedlong
value.StringBuilder
append(long value, int minLength, char prefix)
Appends the string representation of the specifiedlong
value.StringBuilder
append(StringBuilder builder)
StringBuilder
append(StringBuilder builder, int start, int end)
StringBuilder
append(java.lang.CharSequence csq)
Appends the string representation of the specifiedCharSequence
.StringBuilder
append(java.lang.CharSequence csq, int start, int end)
Appends the string representation of the specified subsequence of theCharSequence
.StringBuilder
append(java.lang.Object obj)
Appends the string representation of the specifiedObject
.StringBuilder
append(java.lang.String str)
Appends the contents of the specified string.StringBuilder
append(java.lang.String str, java.lang.String separator)
Appends the specified separator if the builder is not empty, then the specified string.StringBuilder
appendCodePoint(int codePoint)
Appends the encoded Unicode code point.StringBuilder
appendLine(java.lang.String str)
Appends the contents of the specified string, then create a new line.int
capacity()
Returns the number of characters that can be held without growing.char
charAt(int index)
Retrieves the character at theindex
.void
clear()
Sets length to 0.int
codePointAt(int index)
Retrieves the Unicode code point value at theindex
.int
codePointBefore(int index)
Retrieves the Unicode code point value that precedes theindex
.int
codePointCount(int beginIndex, int endIndex)
Calculates the number of Unicode code points betweenbeginIndex
andendIndex
.boolean
contains(java.lang.String subString)
boolean
containsIgnoreCase(java.lang.String subString)
StringBuilder
delete(int start, int end)
Deletes a sequence of characters specified bystart
andend
.StringBuilder
deleteCharAt(int index)
Deletes the character at the specified index.void
ensureCapacity(int min)
Ensures that this object has a minimum capacity available before requiring the internal buffer to be enlarged.boolean
equals(java.lang.Object obj)
boolean
equalsIgnoreCase(StringBuilder other)
boolean
equalsIgnoreCase(java.lang.String other)
void
getChars(int start, int end, char[] dest, int destStart)
Copies the requested sequence of characters to thechar[]
passed starting atdestStart
.int
hashCode()
int
indexOf(java.lang.String string)
Searches for the first index of the specified character.int
indexOf(java.lang.String subString, int start)
Searches for the index of the specified character.int
indexOfIgnoreCase(java.lang.String subString, int start)
StringBuilder
insert(int offset, boolean b)
Inserts the string representation of the specifiedboolean
value at the specifiedoffset
.StringBuilder
insert(int offset, char c)
Inserts the string representation of the specifiedchar
value at the specifiedoffset
.StringBuilder
insert(int offset, char[] ch)
Inserts the string representation of the specifiedchar[]
at the specifiedoffset
.StringBuilder
insert(int offset, char[] str, int strOffset, int strLen)
Inserts the string representation of the specified subsequence of thechar[]
at the specifiedoffset
.StringBuilder
insert(int offset, double d)
Inserts the string representation of the specifieddouble
value at the specifiedoffset
.StringBuilder
insert(int offset, float f)
Inserts the string representation of the specifiedfloat
value at the specifiedoffset
.StringBuilder
insert(int offset, int i)
Inserts the string representation of the specifiedint
value at the specifiedoffset
.StringBuilder
insert(int offset, long l)
Inserts the string representation of the specifiedlong
value at the specifiedoffset
.StringBuilder
insert(int offset, java.lang.CharSequence s)
Inserts the string representation of the specifiedCharSequence
at the specifiedoffset
.StringBuilder
insert(int offset, java.lang.CharSequence s, int start, int end)
Inserts the string representation of the specified subsequence of theCharSequence
at the specifiedoffset
.StringBuilder
insert(int offset, java.lang.Object obj)
Inserts the string representation of the specifiedObject
at the specifiedoffset
.StringBuilder
insert(int offset, java.lang.String str)
Inserts the specified string at the specifiedoffset
.boolean
isEmpty()
int
lastIndexOf(java.lang.String string)
Searches for the last index of the specified character.int
lastIndexOf(java.lang.String subString, int start)
Searches for the index of the specified character.int
length()
The current length.boolean
notEmpty()
static int
numChars(int value, int radix)
static int
numChars(long value, int radix)
int
offsetByCodePoints(int index, int codePointOffset)
Returns the index that is offsetcodePointOffset
code points fromindex
.StringBuilder
replace(char find, java.lang.String replace)
Replaces all instances offind
withreplace
.StringBuilder
replace(int start, int end, java.lang.String str)
Replaces the specified subsequence in this builder with the specified string.StringBuilder
replace(java.lang.String find, java.lang.String replace)
Replaces all instances offind
withreplace
.StringBuilder
reverse()
Reverses the order of characters in this builder.void
setCharAt(int index, char ch)
Sets the character at theindex
.void
setLength(int newLength)
Sets the current length to a new value.java.lang.CharSequence
subSequence(int start, int end)
Returns aCharSequence
of the subsequence from thestart
index to theend
index.java.lang.String
substring(int start)
Returns the String value of the subsequence from thestart
index to the current end.java.lang.String
substring(int start, int end)
Returns the String value of the subsequence from thestart
index to theend
index.java.lang.String
toString()
Returns the current String representation.java.lang.String
toStringAndClear()
Returns the current String representation and clears the StringBuilder.void
trimToSize()
Trims off any extra capacity beyond the current length.
-
-
-
Constructor Detail
-
StringBuilder
public StringBuilder()
Constructs an instance with an initial capacity of16
.- See Also:
capacity()
-
StringBuilder
public StringBuilder(int capacity)
Constructs an instance with the specified capacity.- Parameters:
capacity
- the initial capacity to use.- Throws:
java.lang.NegativeArraySizeException
- if the specifiedcapacity
is negative.- See Also:
capacity()
-
StringBuilder
public StringBuilder(java.lang.CharSequence seq)
Constructs an instance that's initialized with the contents of the specifiedCharSequence
. The capacity of the new builder will be the length of theCharSequence
plus 16.- Parameters:
seq
- theCharSequence
to copy into the builder.- Throws:
java.lang.NullPointerException
- ifseq
isnull
.
-
StringBuilder
public StringBuilder(StringBuilder builder)
-
StringBuilder
public StringBuilder(java.lang.String string)
Constructs an instance that's initialized with the contents of the specifiedString
. The capacity of the new builder will be the length of theString
plus 16.- Parameters:
string
- theString
to copy into the builder.- Throws:
java.lang.NullPointerException
- ifstr
isnull
.
-
-
Method Detail
-
numChars
public static int numChars(int value, int radix)
- Returns:
- the number of characters required to represent the specified value with the specified radix
-
numChars
public static int numChars(long value, int radix)
- Returns:
- the number of characters required to represent the specified value with the specified radix
-
capacity
public int capacity()
Returns the number of characters that can be held without growing.- Returns:
- the capacity
- See Also:
ensureCapacity(int)
,length
-
charAt
public char charAt(int index)
Retrieves the character at theindex
.- Specified by:
charAt
in interfacejava.lang.CharSequence
- Parameters:
index
- the index of the character to retrieve.- Returns:
- the char value.
- Throws:
java.lang.IndexOutOfBoundsException
- ifindex
is negative or greater than or equal to the currentlength()
.
-
ensureCapacity
public void ensureCapacity(int min)
Ensures that this object has a minimum capacity available before requiring the internal buffer to be enlarged. The general policy of this method is that if theminimumCapacity
is larger than the currentcapacity()
, then the capacity will be increased to the largest value of either theminimumCapacity
or the current capacity multiplied by two plus two. Although this is the general policy, there is no guarantee that the capacity will change.- Parameters:
min
- the new minimum capacity to set.
-
getChars
public void getChars(int start, int end, char[] dest, int destStart)
Copies the requested sequence of characters to thechar[]
passed starting atdestStart
.- Parameters:
start
- the inclusive start index of the characters to copy.end
- the exclusive end index of the characters to copy.dest
- thechar[]
to copy the characters to.destStart
- the inclusive start index ofdest
to begin copying to.- Throws:
java.lang.IndexOutOfBoundsException
- if thestart
is negative, thedestStart
is negative, thestart
is greater thanend
, theend
is greater than the currentlength()
ordestStart + end - begin
is greater thandest.length
.
-
length
public int length()
The current length.- Specified by:
length
in interfacejava.lang.CharSequence
- Returns:
- the number of characters contained in this instance.
-
setCharAt
public void setCharAt(int index, char ch)
Sets the character at theindex
.- Parameters:
index
- the zero-based index of the character to replace.ch
- the character to set.- Throws:
java.lang.IndexOutOfBoundsException
- ifindex
is negative or greater than or equal to the currentlength()
.
-
setLength
public void setLength(int newLength)
Sets the current length to a new value. If the new length is larger than the current length, then the new characters at the end of this object will contain thechar
value of
-
-