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
associateWith
Returns a Map where keys are elements from the given array and values are produced by the valueSelector function applied to each element.
associateWithTo
Populates and returns the destination mutable map with key-value pairs for each element of the given array, where key is the element itself and value is provided by the valueSelector function applied to that key.
fun
<
V
,
M
:
MutableMap
<
in
Char
,
in
V
>
>
CharArray
.
associateWithTo
(
destination
:
M
,
valueSelector
:
(
Char
)
->
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
?
flatMapIndexedTo
Appends all elements yielded from results of transform function being invoked on each element and its index in the original array, to the given destination .
fun
<
R
,
C
:
MutableCollection
<
in
R
>
>
CharArray
.
flatMapIndexedTo
(
destination
:
C
,
transform
:
(
index
:
Int
,
Char
)
->
Iterable
<
R
>
)
:
C
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
maxByOrNull
Returns the first element yielding the largest value of the given function or
null
if there are no elements.
fun
<
R
:
Comparable
<
R
>
>
CharArray
.
maxByOrNull
(
selector
:
(
Char
)
->
R
)
:
Char
?
maxOf
Returns the largest value among all values produced by selector function applied to each element in the array.
fun
<
R
:
Comparable
<
R
>
>
any_array
<R>
.
maxOf
(
selector
:
(
Char
)
->
R
)
:
R
maxOfOrNull
Returns the largest value among all values produced by
selector
function
applied to each element in the array or
null
if there are no elements.
fun
<
R
:
Comparable
<
R
>
>
any_array
<R>
.
maxOfOrNull
(
selector
:
(
Char
)
->
R
)
:
R
?
maxOfWith
Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the array.
fun
<
R
>
CharArray
.
maxOfWith
(
comparator
:
Comparator
<
in
R
>
,
selector
:
(
Char
)
->
R
)
:
R
maxOfWithOrNull
Returns the largest value according to the provided
comparator
among all values produced by
selector
function applied to each element in the array or
null
if there are no elements.
fun
<
R
>
CharArray
.
maxOfWithOrNull
(
comparator
:
Comparator
<
in
R
>
,
selector
:
(
Char
)
->
R
)
:
R
?
maxOrNull
Returns the largest element or
null
if there are no elements.
fun
CharArray
.
maxOrNull
(
)
:
Char
?
maxWith
Returns the first element having the largest value according to the provided comparator .
fun
CharArray
.
maxWith
(
comparator
:
Comparator
<
in
Char
>
)
:
Char
fun
CharArray
.
maxWith
(
comparator
:
Comparator
<
in
Char
>
)
:
Char
?
maxWithOrNull
Returns the first element having the largest value according to the provided
comparator
or
null
if there are no elements.
fun
CharArray
.
maxWithOrNull
(
comparator
:
Comparator
<
in
Char
>
)
:
Char
?
minByOrNull
Returns the first element yielding the smallest value of the given function or
null
if there are no elements.
fun
<
R
:
Comparable
<
R
>
>
CharArray
.
minByOrNull
(
selector
:
(
Char
)
->
R
)
:
Char
?
minOf
Returns the smallest value among all values produced by selector function applied to each element in the array.
fun
<
R
:
Comparable
<
R
>
>
any_array
<R>
.
minOf
(
selector
:
(
Char
)
->
R
)
:
R
minOfOrNull
Returns the smallest value among all values produced by
selector
function
applied to each element in the array or
null
if there are no elements.
fun
<
R
:
Comparable
<
R
>
>
any_array
<R>
.
minOfOrNull
(
selector
:
(
Char
)
->
R
)
:
R
?
minOfWith
Returns the smallest value according to the provided comparator among all values produced by selector function applied to each element in the array.
fun
<
R
>
CharArray
.
minOfWith
(
comparator
:
Comparator
<
in
R
>
,
selector
:
(
Char
)
->
R
)
:
R
minOfWithOrNull
Returns the smallest value according to the provided
comparator
among all values produced by
selector
function applied to each element in the array or
null
if there are no elements.
fun
<
R
>
CharArray
.
minOfWithOrNull
(
comparator
:
Comparator
<
in
R
>
,
selector
:
(
Char
)
->
R
)
:
R
?
minOrNull
Returns the smallest element or
null
if there are no elements.
fun
CharArray
.
minOrNull
(
)
:
Char
?
minWith
Returns the first element having the smallest value according to the provided comparator .
fun
CharArray
.
minWith
(
comparator
:
Comparator
<
in
Char
>
)
:
Char
fun
CharArray
.
minWith
(
comparator
:
Comparator
<
in
Char
>
)
:
Char
?
minWithOrNull
Returns the first element having the smallest value according to the provided
comparator
or
null
if there are no elements.
fun
CharArray
.
minWithOrNull
(
comparator
:
Comparator
<
in
Char
>
)
:
Char
?
randomOrNull
Returns a random element from this array, or
null
if this array is empty.
fun
CharArray
.
randomOrNull
(
)
:
Char
?
refTo
fun
CharArray
.
refTo
(
index
:
Int
)
:
CValuesRef
<
COpaque
>
reverse
Reverses elements in the array in-place.
fun
CharArray
.
reverse
(
)
Reverses elements of the array in the specified range in-place.
fun
CharArray
.
reverse
(
fromIndex
:
Int
,
toIndex
:
Int
)
runningFoldIndexed
runningReduceIndexed
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.
scanIndexed
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 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
(
)
Sorts elements of the array in the specified range in-place. The elements are sorted descending according to their natural sort order.
fun
CharArray
.
sortDescending
(
fromIndex
:
Int
,
toIndex
:
Int
)
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
>
sumOf
Returns the sum of all values produced by selector function applied to each element in the array.
fun
CharArray
.
sumOf
(
selector
:
(
Char
)
->
Double
)
:
Double
fun
CharArray
.
sumOf
(
selector
:
(
Char
)
->
Int
)
:
Int
fun
CharArray
.
sumOf
(
selector
:
(
Char
)
->
Long
)
:
Long
fun
CharArray
.
sumOf
(
selector
:
(
Char
)
->
BigDecimal
)
:
BigDecimal
fun
CharArray
.
sumOf
(
selector
:
(
Char
)
->
BigInteger
)
:
BigInteger
toCollection
Appends all elements to the given destination collection.
fun
<
C
:
MutableCollection
<
in
Char
>
>
CharArray
.
toCollection
(
destination
:
C
)
:
C
toMutableList
Returns a new MutableList filled with all elements of this array.
fun
CharArray
.
toMutableList
(
)
:
MutableList
<
Char
>
toMutableSet
Returns a new MutableSet 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.