APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.utils

public Class CharArray

extends Object
implements CharSequence, Appendable
Class Inheritance
All Implemented Interfaces
java.lang.Appendable, java.lang.CharSequence
Imports
java.io.IOException, .Reader, .Writer, java.nio.CharBuffer, java.util.Arrays, .Iterator, .Objects, com.badlogic.gdx.math.MathUtils

A resizable, ordered or unordered char array. Avoids the boxing that occurs with ArrayList. If unordered, this class avoids a memory copy when removing single chars (the last element is moved to the removed element's position).

This class provides a more flexible and powerful API than StringBuffer and StringBuilder, the main differences being:

Authors
Nathan Sweet, org.apache.commons.text.TextStringBuilder

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
pack-priv class

Field Summary

Modifier and TypeField and Description
private static final int
private static final char[]
private static final int
private static final int
public char[]
private static final int
MAX_BUFFER_SIZE

The maximum buffer size to allocate.

private static final String
public boolean
public int
private static final int

Constructor Summary

AccessConstructor and Description
public
CharArray()

Creates an ordered array with a capacity of 16.

public
CharArray(int capacity)

Creates an ordered array with the specified capacity.

public
CharArray(boolean
If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
ordered
,
int
Any elements added beyond this will cause the backing array to be grown.
capacity
)

public
CharArray(CharArray array)

Creates a new array containing the elements in the specific array.

public
CharArray(char[] array)

Creates a new ordered array containing the elements in the specified array.

public
CharArray(boolean
If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
ordered
,
char[] array, int start, int count)

Creates a new array containing the elements in the specified array.

public
CharArray(CharSequence seq)

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

public
CharArray(String str)

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

public
CharArray(StringBuilder str)

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

private
CharArray(char[] initialBuffer, int length)

Constructs an instance that uses the specified array directly, until reallocation is needed.

Method Summary

Modifier and TypeMethod and Description
public void
add(char value)

public void
add(char value1, char value2)

public void
add(char value1, char value2, char value3)

public void
add(char value1, char value2, char value3, char value4)

public void
public void
addAll(CharArray array, int offset, int length)

public void
addAll(char... array)

public void
addAll(char[] array, int offset, int length)

public CharArray
append(boolean value)

Appends a boolean value to this CharArray.

public CharArray
append(char value)

Implements java.lang.Appendable.append.

Appends a char value to this CharArray.

public CharArray
append(char[] ch)

Appends a char array to this CharArray.

public CharArray
append(char[] ch, int
the start index, inclusive
start
,
int length)

Appends a char array to this CharArray.

public CharArray
append(CharBuffer str)

Appends the contents of a char buffer to this CharArray.

public CharArray
append(CharBuffer buf, int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Appends the contents of a char buffer to this CharArray.

public CharArray
append(CharSequence seq)

Implements java.lang.Appendable.append.

Appends a CharSequence to this CharArray.

public CharArray
append(CharSequence seq, int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Implements java.lang.Appendable.append.

Appends part of a CharSequence to this CharArray.

public CharArray
append(double value)

Appends a double value to this CharArray using String.valueOf.

public CharArray
append(float value)

Appends a float value to this CharArray using String.valueOf.

public CharArray
append(int value)

Appends an int value to this CharArray.

public CharArray
append(int value, int
the minimum number of characters to add
minLength
)

Appends the string representation of the specified int value.

public CharArray
append(int value, final int
the minimum number of characters to add
minLength
,
final char
the character to use as prefix
prefix
)

Appends the string representation of the specified int value.

public CharArray
append(long value)

Appends a long value to this CharArray.

public CharArray
append(long value, int
the minimum number of characters to add
minLength
)

Appends the string representation of the specified long value.

public CharArray
append(long value, int
the minimum number of characters to add
minLength
,
char
the character to use as prefix
prefix
)

Appends the string representation of the specified long value.

public CharArray
append(Object obj)

Appends an object to this CharArray.

public CharArray
append(String str)

Appends a string to this CharArray.

public CharArray
append(String str, String separator)

Appends the specified separator if this CharArray is not empty, then the specified string.

public CharArray
append(String str, int
the start index, inclusive
start
,
int end)

Appends part of a string to this CharArray.

public CharArray
append(StringBuffer str)

Appends a string buffer to this CharArray.

public CharArray
append(StringBuffer str, int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Appends part of a string buffer to this CharArray.

public CharArray
append(StringBuilder str)

Appends a StringBuilder to this CharArray.

public CharArray
append(StringBuilder str, int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Appends part of a StringBuilder to this CharArray.

public CharArray
append(CharArray str)

Appends another CharArray to this CharArray.

public CharArray
append(CharArray str, int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Appends part of a CharArray to this CharArray.

public CharArray
appendAll(Iterable<?> iterable)

Appends each item in an iterable to this CharArray without any separators.

public CharArray
appendAll(Iterator<?> iter)

Appends each item in an iterator to this CharArray without any separators.

public final <T> CharArray
appendAll(T... array)

Appends each item in an array to this CharArray without any separators.

public CharArray
appendCodePoint(int codePoint)

Appends the encoded Unicode code point.

private void
appendFalse(int index)

Appends "false".

public CharArray
appendFixedWidthPadLeft(int value, int
the fixed field width, zero or negative has no effect
width
,
char padChar)

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

public CharArray
appendFixedWidthPadLeft(Object
the object to append, null uses ""
obj
,
int
the fixed field width, zero or negative has no effect
width
,
char padChar)

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

public CharArray
appendFixedWidthPadRight(int value, int
the fixed field width, zero or negative has no effect
width
,
char padChar)

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

public CharArray
appendFixedWidthPadRight(Object
the object to append, null uses "null"
obj
,
int
the fixed field width, zero or negative has no effect
width
,
char padChar)

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

public CharArray
appendLine(String str)

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

public CharArray
appendLine()

Appends \n.

public CharArray
appendln(boolean value)

Appends a boolean value followed by a new line to this CharArray.

public CharArray
appendln(char ch)

Appends a char value followed by a new line to this CharArray.

public CharArray
appendln(char[] ch)

Appends a char array followed by a new line to this CharArray.

public CharArray
appendln(char[] ch, int
the start index, inclusive
start
,
int length)

Appends a char array followed by a new line to this CharArray.

public CharArray
appendln(double value)

Appends a double value followed by a new line to this CharArray using String.valueOf.

public CharArray
appendln(float value)

Appends a float value followed by a new line to this CharArray using String.valueOf.

public CharArray
appendln(int value)

Appends an int value followed by a new line to this CharArray using String.valueOf.

public CharArray
appendln(long value)

Appends a long value followed by a new line to this CharArray using String.valueOf.

public CharArray
appendln(Object obj)

Appends an object followed by a new line to this CharArray.

public CharArray
appendln(String str)

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

public CharArray
appendln(String str, int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

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

public CharArray
appendln(StringBuffer str)

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

public CharArray
appendln(StringBuffer str, int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

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

public CharArray
appendln(StringBuilder str)

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

public CharArray
appendln(StringBuilder str, int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

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

public CharArray
appendln(CharArray str)

Appends another CharArray followed by a new line to this CharArray.

public CharArray
appendln(CharArray str, int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Appends part of a CharArray followed by a new line to this CharArray.

public CharArray
appendln()

Appends \n.

public CharArray
appendNull()

Appends "null".

public CharArray
appendPadding(int
negative means no append
padCount
,
char padChar)

Appends the pad character to this CharArray the specified number of times.

public CharArray
appendSeparator(char separator)

Appends a separator if this CharArray is currently non-empty.

public CharArray
appendSeparator(char
the separator if this CharArray is not empty
standard
,
char
the separator if this CharArray is empty
defaultIfEmpty
)

Appends one of both separators to this CharArray If this CharArray is currently empty it will append the defaultIfEmpty-separator Otherwise it will append the standard-separator The separator is appended using append(char).

public CharArray
appendSeparator(char separator, int loopIndex)

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

public CharArray
appendSeparator(String
the separator to use, null means no separator
separator
)

Appends a separator if this CharArray is currently non-empty.

public CharArray
appendSeparator(String
the separator to use, null means no separator
separator
,
int loopIndex)

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

public CharArray
appendSeparator(String
the separator if this CharArray is not empty, null means no separator
standard
,
String
the separator if this CharArray is empty, null means no separator
defaultIfEmpty
)

Appends one of both separators to this CharArray.

public void
appendTo(Appendable appendable)

Appends current contents of this CharArray to the provided Appendable.

private void
appendTrue(int index)

Appends "true".

public CharArray
appendWithSeparators(Iterable<?> iterable, String
the separator to use, null means no separator
separator
)

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

public CharArray
appendWithSeparators(Iterator<?> it, String
the separator to use, null means no separator
separator
)

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

public CharArray
appendWithSeparators(Object[] array, String
the separator to use, null means no separator
separator
)

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

public int
public char

Returns:

The character at the index
charAt
(int index)

Implements java.lang.CharSequence.charAt.

Gets the character at the specified index.

public void
clear()

Clears this CharArray.

public int

Returns:

the Unicode code point value.
codePointAt
(int
the index to the char code unit.
index
)

Retrieves the Unicode code point value at the index.

public int

Returns:

the Unicode code point value.
codePointBefore
(int
the index to the char code unit within this object.
index
)

Retrieves the Unicode code point value that precedes the index.

public int

Returns:

the number of Unicode code points in the subsequence.
codePointCount
(int
the inclusive beginning index of the subsequence.
begin
,
int
the exclusive end index of the subsequence.
end
)

Calculates the number of Unicode code points between begin and end.

public boolean
contains(char value)

public boolean

Returns:

true if this CharArray contains the string
contains
(String str)

Tests if this CharArray contains the specified string.

public boolean
public CharArray
delete(int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Deletes the characters between the two specified indices.

private void
delete(int
the start index
start
,
int
the end index (exclusive)
end
,
int
the length
length
)

Internal method to delete a range without validation.

public CharArray
deleteAll(char ch)

Deletes the character wherever it occurs in the CharArray.

public CharArray
deleteAll(String str)

Deletes the string wherever it occurs in the CharArray.

public CharArray
deleteCharAt(int index)

Deletes the character at the specified index.

public CharArray
deleteFirst(char ch)

Deletes the character wherever it occurs in the CharArray.

public CharArray
deleteFirst(String str)

Deletes the string wherever it occurs in the CharArray.

public char

Returns:

The character at the index
drainChar
(int index)

Gets the character at the specified index before deleting it.

public int

Returns:

How many characters were copied (then deleted). If this CharArray is empty, return 0.
drainChars
(int
first index to copy, inclusive.
start
,
int
last index to copy, exclusive.
end
,
char[]
the target array.
target
,
int
the index to start copying in the target.
targetIndex
)

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

public boolean

Returns:

true if this CharArray ends with the string
endsWith
(String str)

Checks whether this CharArray ends with the specified string.

public char[]

Returns:

items
ensureCapacity
(int additionalCapacity)

Increases the size of the backing array to accommodate at least the specified number of additional items.

public boolean

Returns:

true if the CharArrays contain the same characters in the same order
equals
(Object
the object to check, null returns false
object
)

Overrides java.lang.Object.equals.

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

public boolean

Returns:

true if the CharArrays contain the same characters in the same order
equals
(CharArray
the object to check, null returns false
other
)

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

public boolean

Returns:

true if the CharArrays contain the same characters in the same order
equalsIgnoreCase
(CharArray
the object to check, null returns false
other
)

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

public boolean
public boolean
public char
first()

Returns the first item.

public char
get(int index)

public char[]

Returns:

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

Copies this character array into the specified array.

public void
getChars(int
first index to copy, inclusive.
start
,
int
last index to copy, exclusive.
end
,
char[]
the target array, must not too small.
target
,
int
the index to start copying in target.
targetIndex
)

Overrides default java.lang.CharSequence.getChars.

Copies this character array into the specified array.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public void
incr(int index, char value)

public void
incr(char value)

public int
indexOf(char value)

public int

Returns:

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

Searches this CharArray to find the first reference to the specified char.

public int

Returns:

The first index of the string, or -1 if not found
indexOf
(String str)

Searches this CharArray to find the first reference to the specified string.

public int

Returns:

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

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

public int
indexOfIgnoreCase(String str, int start)

public CharArray
insert(int index, boolean value)

Inserts the value into this CharArray.

public void
insert(int index, char value)

public CharArray
insert(int index, char[] ch)

Inserts the character array into this CharArray.

public CharArray
insert(int index, char[] ch, int
the offset into the character array to start at
offset
,
int
the length of the character array part to copy
length
)

Inserts part of the character array into this CharArray.

public CharArray
insert(int index, double value)

Inserts the value into this CharArray.

public CharArray
insert(int index, float value)

Inserts the value into this CharArray.

public CharArray
insert(int index, int value)

Inserts the value into this CharArray.

public CharArray
insert(int index, long value)

Inserts the value into this CharArray.

public CharArray
insert(int index, Object obj)

Inserts the string representation of an object into this CharArray.

public CharArray
insert(int index, String str)

Inserts the string into this CharArray.

public void
insertRange(int index, int count)

Inserts the specified number of items at the specified index.

public boolean
isEmpty()

Overrides default java.lang.CharSequence.isEmpty.

Returns true if the array is empty.

public int
lastIndexOf(char value)

public int

Returns:

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

Searches this CharArray to find the last reference to the specified char.

public int

Returns:

The last index of the string, or -1 if not found
lastIndexOf
(String str)

Searches this CharArray to find the last reference to the specified string.

public int

Returns:

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

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

public String

Returns:

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

Extracts the leftmost characters from this CharArray without throwing an exception.

public int

Returns:

The length
length
()

Implements java.lang.CharSequence.length.

Gets the length of this CharArray.

public String

Returns:

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

Extracts some characters from the middle of this CharArray without throwing an exception.

public void
mul(int index, char value)

public void
mul(char value)

public boolean
notEmpty()

Returns true if the array has one or more items.

public static int
numChars(int value, int radix)

Returns: the number of characters required to represent the value with the specified radix

public static int
numChars(long value, int radix)

Returns: the number of characters required to represent the value with the specified radix

public int

Returns:

the index that is codePointOffset code points away from index.
offsetByCodePoints
(int
the index to calculate the offset from.
index
,
int
the number of code points to count.
codePointOffset
)

Returns the index that is offset codePointOffset code points from index.

public char
peek()

Returns the last item.

public char
pop()

Removes and returns the last item.

public char
random()

Returns a random item from the array, or ((char)0) if the array is empty.

public Reader

Returns:

a reader that reads from this CharArray
reader
()

Gets the contents of this CharArray as a Reader.

public int

Returns:

The number of characters read.
readFrom
(CharBuffer charBuffer)

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

public int

Returns:

The number of characters read
readFrom
(Readable readable)

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

public int

Returns:

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

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

public int

Returns:

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

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

public boolean

Returns:

true if this array was modified.
removeAll
(CharArray array)

Removes from this array the first instance of each element contained in the specified array.

public char
removeIndex(int index)

Removes and returns the item at the specified index.

public void
removeRange(int start, int end)

Removes the items between the specified indices, inclusive.

public boolean
removeValue(char value)

Removes the first occurrence of the specified value.

public CharArray
replace(int
the start index, inclusive
start
,
int
the end index, exclusive
end
,
String
the string to replace with
replaceStr
)

Replaces a portion of this CharArray with another string.

public CharArray
replace(char find, String replace)

Replaces the search char with the replace string throughout this CharArray.

private void
replace(int
the start index
start
,
int
the end index (exclusive)
end
,
int
the length to remove (end - start)
removeLength
,
String
the string to replace with, can be null if insertLen is 0
insertStr
,
int
the length of the insert string
insertLength
)

Internal method to delete a range without validation.

public int

Returns:

the number of replacements done
replaceAll
(char
the char to be replaced
value
,
char
all occurrences of value will be replaced by this replacement
replacement
)

Returns the number of replacements done.

public CharArray
replaceAll(String searchStr, String replaceStr)

Replaces the search string with the replace string throughout this CharArray.

public boolean

Returns:

if value was found and replaced
replaceFirst
(char
the char to be replaced
value
,
char
the first value will be replaced by this replacement if found
replacement
)

Returns true if the specified value was replaced successfully with the replacement

public CharArray
replaceFirst(String searchStr, String
the replace string, null is equivalent to an empty string
replaceStr
)

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

private void
require(int additionalCapacity)

protected char[]
resize(int newSize)

private void
resizeBuffer(int minCapacity)

Resizes the buffer to at least the size specified.

public void
public CharArray
reverseCodePoints()

Reverses this CharArray, keeping surrogate pairs together.

public String

Returns:

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

Extracts the rightmost characters from this CharArray without throwing an exception.

public void
set(int index, char value)

public CharArray
set(CharSequence str)

Clears and sets this CharArray to the given value.

public CharArray
setCharAt(int index, char ch)

Sets the character at the specified index.

public CharArray
setLength(int
the length to set to, must be zero or positive
length
)

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

public char[]

Returns:

items
setSize
(int newSize)

Sets the array size, leaving any values beyond the current size undefined.

public char[]

Returns:

items
shrink
()

Reduces the size of the backing array to the size of the actual items.

public void
public void
sort()

public boolean

Returns:

true if this CharArray starts with the string
startsWith
(String
the string to search for, null returns false
str
)

Checks whether this CharArray starts with the specified string.

public CharSequence
subSequence(int start, int end)

Implements java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence.

public String

Returns:

The new string
substring
(int
the start index, inclusive
start
)

Extracts a portion of this CharArray as a string.

public String

Returns:

The new string
substring
(int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Extracts a portion of this CharArray as a string.

public void
swap(int first, int second)

public char[]
public char[]

Returns:

a new array that represents the contents of this CharArray
toCharArray
()

Copies this CharArray's character array into a new character array.

public char[]

Returns:

a new array that holds part of the contents of this CharArray
toCharArray
(int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Copies part of this CharArray's character array into a new character array.

public String
toString()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Returns a String version of this CharArray, creating a new instance each time the method is called.

public String
toString(String separator)

public String

Returns:

a String containing the characters in this instance.
toStringAndClear
()

Returns the current String representation and clears this CharArray.

public CharArray
trim()

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

public void
trimToSize()

Resizes items if its length is more than size.

public void
truncate(int newSize)

Reduces the size of the array to the specified size.

protected void
validateIndex(int index)

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

protected int

Returns:

A valid end index.
validateRange
(int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Validates parameters defining a range of this CharArray.

public static CharArray
with(char... array)

public static CharArray

Returns:

A new instance.
wrap
(char[]
The initial array that will back the new CharArray.
initialBuffer
)

Constructs an instance from a reference to a character array.

public static CharArray

Returns:

A new instance.
wrap
(char[]
The initial array that will back the new CharArray.
initialBuffer
,
int
The length of the subarray to be used; must be non-negative and no larger than initialBuffer.length. The new CharArray's size will be set to length.
length
)

Constructs an instance from a reference to a character array.

public Writer

Returns:

a writer that populates this CharArray
writer
()

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

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait