CharArray
For Common, JVM, JS
An array of chars. When targeting the JVM, instances of this class are represented as char[]
.
For Native
An array of chars.
Constructors
Properties
size
Returns the number of elements in the array.
val size: Int
Functions
get
Returns the array element at the given index. This method can be called using the index operator.
operator fun get(index: Int): Char
iterator
Creates an iterator over the elements of the array.
operator fun iterator(): CharIterator
Extension Properties
Extension Functions
associateBy
Returns a Map containing the elements from the given array indexed by the key returned from keySelector function applied to each element.
Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given array.
associateByTo
Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function applied to each element of the given array and value is the element itself.
fun <K, M : MutableMap<in K, in Char>> CharArray.associateByTo(
destination: M,
keySelector: (Char) -> K
): M
Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function and and value is provided by the valueTransform function applied to elements of the given array.
fun <K, V, M : MutableMap<in K, in V>> CharArray.associateByTo(
destination: M,
keySelector: (Char) -> K,
valueTransform: (Char) -> V
): M
associateTo
Populates and returns the destination mutable map with key-value pairs provided by transform function applied to each element of the given array.
fun <K, V, M : MutableMap<in K, in V>> CharArray.associateTo(
destination: M,
transform: (Char) -> Pair<K, V>
): M
component1
Returns 1st element from the array.
operator fun CharArray.component1(): Char
component2
Returns 2nd element from the array.
operator fun CharArray.component2(): Char
component3
Returns 3rd element from the array.
operator fun CharArray.component3(): Char
component4
Returns 4th element from the array.
operator fun CharArray.component4(): Char
component5
Returns 5th element from the array.
operator fun CharArray.component5(): Char
elementAtOrElse
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this array.
fun CharArray.elementAtOrElse(
index: Int,
defaultValue: (Int) -> Char
): Char
filterIndexedTo
Appends all elements matching the given predicate to the given destination.
fun <C : MutableCollection<in Char>> CharArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Char) -> Boolean
): C
filterNotTo
Appends all elements not matching the given predicate to the given destination.
fun <C : MutableCollection<in Char>> CharArray.filterNotTo(
destination: C,
predicate: (Char) -> Boolean
): C
filterTo
Appends all elements matching the given predicate to the given destination.
fun <C : MutableCollection<in Char>> CharArray.filterTo(
destination: C,
predicate: (Char) -> Boolean
): C
firstOrNull
Returns the first element, or null
if the array is empty.
fun CharArray.firstOrNull(): Char?
flatMapTo
Appends all elements yielded from results of transform function being invoked on each element of original array, to the given destination.
fun <R, C : MutableCollection<in R>> CharArray.flatMapTo(
destination: C,
transform: (Char) -> Iterable<R>
): C
getOrElse
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this array.
fun CharArray.getOrElse(
index: Int,
defaultValue: (Int) -> Char
): Char
groupBy
Groups elements of the original array by the key returned by the given keySelector function applied to each element and returns a map where each group key is associated with a list of corresponding elements.
Groups values returned by the valueTransform function applied to each element of the original array by the key returned by the given keySelector function applied to the element and returns a map where each group key is associated with a list of corresponding values.
groupByTo
Groups elements of the original array by the key returned by the given keySelector function applied to each element and puts to the destination map each group key associated with a list of corresponding elements.
fun <K, M : MutableMap<in K, MutableList<Char>>> CharArray.groupByTo(
destination: M,
keySelector: (Char) -> K
): M
Groups values returned by the valueTransform function applied to each element of the original array by the key returned by the given keySelector function applied to the element and puts to the destination map each group key associated with a list of corresponding values.
fun <K, V, M : MutableMap<in K, MutableList<V>>> CharArray.groupByTo(
destination: M,
keySelector: (Char) -> K,
valueTransform: (Char) -> V
): M
isNotEmpty
Returns true
if the array is not empty.
fun CharArray.isNotEmpty(): Boolean
joinTo
Appends the string from all the elements separated using separator and using the given prefix and postfix if supplied.
fun <A : Appendable> CharArray.joinTo(
buffer: A,
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = "...",
transform: ((Char) -> CharSequence)? = null
): A
joinToString
Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.
fun CharArray.joinToString(
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = "...",
transform: ((Char) -> CharSequence)? = null
): String
lastOrNull
Returns the last element, or null
if the array is empty.
fun CharArray.lastOrNull(): Char?
mapIndexedTo
Applies the given transform function to each element and its index in the original array and appends the results to the given destination.
fun <R, C : MutableCollection<in R>> CharArray.mapIndexedTo(
destination: C,
transform: (index: Int, Char) -> R
): C
mapTo
Applies the given transform function to each element of the original array and appends the results to the given destination.
fun <R, C : MutableCollection<in R>> CharArray.mapTo(
destination: C,
transform: (Char) -> R
): C
maxBy
Returns the first element yielding the largest value of the given function or null
if there are no elements.
fun <R : Comparable<R>> CharArray.maxBy(
selector: (Char) -> R
): Char?
maxWith
Returns the first element having the largest value according to the provided comparator or null
if there are no elements.
fun CharArray.maxWith(comparator: Comparator<in Char>): Char?
minBy
Returns the first element yielding the smallest value of the given function or null
if there are no elements.
fun <R : Comparable<R>> CharArray.minBy(
selector: (Char) -> R
): Char?
minWith
Returns the first element having the smallest value according to the provided comparator or null
if there are no elements.
fun CharArray.minWith(comparator: Comparator<in Char>): Char?
randomOrNull
Returns a random element from this array, or null
if this array is empty.
fun CharArray.randomOrNull(): Char?
scanIndexed
scanReduceIndexed
Returns a list containing successive accumulation values generated by applying operation from left to right to each element, its index in the original array and current accumulator value that starts with the first element of this array.
single
Returns the single element, or throws an exception if the array is empty or has more than one element.
fun CharArray.single(): Char
singleOrNull
Returns single element, or null
if the array is empty or has more than one element.
fun CharArray.singleOrNull(): Char?
sliceArray
Returns an array containing elements of this array at specified indices.
fun CharArray.sliceArray(indices: Collection<Int>): CharArray
sort
Sorts a range in the array in-place.
fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size)
Sorts the array in-place according to the order specified by the given comparison function.
fun CharArray.sort(comparison: (a: Char, b: Char) -> Int)
sortDescending
Sorts elements in the array in-place descending according to their natural sort order.
fun CharArray.sortDescending()
sortedBy
Returns a list of all elements sorted according to natural sort order of the value returned by specified selector function.
fun <R : Comparable<R>> CharArray.sortedBy(
selector: (Char) -> R?
): List<Char>
sortedByDescending
Returns a list of all elements sorted descending according to natural sort order of the value returned by specified selector function.
fun <R : Comparable<R>> CharArray.sortedByDescending(
selector: (Char) -> R?
): List<Char>
sortedWith
Returns a list of all elements sorted according to the specified comparator.
fun CharArray.sortedWith(
comparator: Comparator<in Char>
): List<Char>
toCollection
Appends all elements to the given destination collection.
fun <C : MutableCollection<in Char>> CharArray.toCollection(
destination: C
): C
toMutableList
Returns a MutableList filled with all elements of this array.
fun CharArray.toMutableList(): MutableList<Char>
toMutableSet
Returns a mutable set containing all distinct elements from the given array.
fun CharArray.toMutableSet(): MutableSet<Char>
withIndex
Returns a lazy Iterable that wraps each element of the original array into an IndexedValue containing the index of that element and the element itself.
fun CharArray.withIndex(): Iterable<IndexedValue<Char>>
zip
Returns a list of pairs built from the elements of this
array and the other array with the same index.
The returned list has length of the shortest collection.
Returns a list of values built from the elements of this
array and the other array with the same index
using the provided transform function applied to each pair of elements.
The returned list has length of the shortest collection.
Returns a list of pairs built from the elements of this
collection and other array with the same index.
The returned list has length of the shortest collection.
Returns a list of values built from the elements of this
array and the other collection with the same index
using the provided transform function applied to each pair of elements.
The returned list has length of the shortest collection.