ByteArray
For Common, JVM, JS
An array of bytes. When targeting the JVM, instances of this class are represented as byte[].
For Native
An array of bytes.
Constructors
Properties
size
Returns the number of elements in the array.
val size: IntFunctions
get
Returns the array element at the given index. This method can be called using the index operator.
operator fun get(index: Int): Byteiterator
Creates an iterator over the elements of the array.
operator fun iterator(): ByteIteratorExtension 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 Byte>> ByteArray.associateByTo(
destination: M,
keySelector: (Byte) -> K
): MPopulates 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>> ByteArray.associateByTo(
destination: M,
keySelector: (Byte) -> K,
valueTransform: (Byte) -> V
): MassociateTo
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>> ByteArray.associateTo(
destination: M,
transform: (Byte) -> Pair<K, V>
): MasUByteArray
Returns an array of type UByteArray, which is a view of this array where each element is an unsigned reinterpretation of the corresponding element of this array.
fun ByteArray.asUByteArray(): UByteArraycomponent1
Returns 1st element from the array.
operator fun ByteArray.component1(): Bytecomponent2
Returns 2nd element from the array.
operator fun ByteArray.component2(): Bytecomponent3
Returns 3rd element from the array.
operator fun ByteArray.component3(): Bytecomponent4
Returns 4th element from the array.
operator fun ByteArray.component4(): Bytecomponent5
Returns 5th element from the array.
operator fun ByteArray.component5(): ByteelementAtOrElse
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 ByteArray.elementAtOrElse(
index: Int,
defaultValue: (Int) -> Byte
): BytefilterIndexedTo
Appends all elements matching the given predicate to the given destination.
fun <C : MutableCollection<in Byte>> ByteArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Byte) -> Boolean
): CfilterNotTo
Appends all elements not matching the given predicate to the given destination.
fun <C : MutableCollection<in Byte>> ByteArray.filterNotTo(
destination: C,
predicate: (Byte) -> Boolean
): CfilterTo
Appends all elements matching the given predicate to the given destination.
fun <C : MutableCollection<in Byte>> ByteArray.filterTo(
destination: C,
predicate: (Byte) -> Boolean
): CfirstOrNull
Returns the first element, or null if the array is empty.
fun ByteArray.firstOrNull(): Byte?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>> ByteArray.flatMapTo(
destination: C,
transform: (Byte) -> Iterable<R>
): CgetOrElse
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 ByteArray.getOrElse(
index: Int,
defaultValue: (Int) -> Byte
): BytegroupBy
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<Byte>>> ByteArray.groupByTo(
destination: M,
keySelector: (Byte) -> K
): MGroups 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>>> ByteArray.groupByTo(
destination: M,
keySelector: (Byte) -> K,
valueTransform: (Byte) -> V
): MinputStream
Creates an input stream for reading data from this byte array.
fun ByteArray.inputStream(): ByteArrayInputStreamCreates an input stream for reading data from the specified portion of this byte array.
fun ByteArray.inputStream(
offset: Int,
length: Int
): ByteArrayInputStreamisNotEmpty
Returns true if the array is not empty.
fun ByteArray.isNotEmpty(): BooleanjoinTo
Appends the string from all the elements separated using separator and using the given prefix and postfix if supplied.
fun <A : Appendable> ByteArray.joinTo(
buffer: A,
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = "...",
transform: ((Byte) -> CharSequence)? = null
): AjoinToString
Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.
fun ByteArray.joinToString(
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = "...",
transform: ((Byte) -> CharSequence)? = null
): StringlastOrNull
Returns the last element, or null if the array is empty.
fun ByteArray.lastOrNull(): Byte?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>> ByteArray.mapIndexedTo(
destination: C,
transform: (index: Int, Byte) -> R
): CmapTo
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>> ByteArray.mapTo(
destination: C,
transform: (Byte) -> R
): CmaxBy
Returns the first element yielding the largest value of the given function or null if there are no elements.
fun <R : Comparable<R>> ByteArray.maxBy(
selector: (Byte) -> R
): Byte?maxWith
Returns the first element having the largest value according to the provided comparator or null if there are no elements.
fun ByteArray.maxWith(comparator: Comparator<in Byte>): Byte?minBy
Returns the first element yielding the smallest value of the given function or null if there are no elements.
fun <R : Comparable<R>> ByteArray.minBy(
selector: (Byte) -> R
): Byte?minWith
Returns the first element having the smallest value according to the provided comparator or null if there are no elements.
fun ByteArray.minWith(comparator: Comparator<in Byte>): Byte?randomOrNull
Returns a random element from this array, or null if this array is empty.
fun ByteArray.randomOrNull(): Byte?refTo
fun ByteArray.refTo(index: Int): CValuesRef<ByteVar>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 ByteArray.single(): BytesingleOrNull
Returns single element, or null if the array is empty or has more than one element.
fun ByteArray.singleOrNull(): Byte?sliceArray
Returns an array containing elements of this array at specified indices.
fun ByteArray.sliceArray(indices: Collection<Int>): ByteArraysort
Sorts a range in the array in-place.
fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size)Sorts the array in-place according to the order specified by the given comparison function.
fun ByteArray.sort(comparison: (a: Byte, b: Byte) -> Int)sortDescending
Sorts elements in the array in-place descending according to their natural sort order.
fun ByteArray.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>> ByteArray.sortedBy(
selector: (Byte) -> R?
): List<Byte>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>> ByteArray.sortedByDescending(
selector: (Byte) -> R?
): List<Byte>sortedWith
Returns a list of all elements sorted according to the specified comparator.
fun ByteArray.sortedWith(
comparator: Comparator<in Byte>
): List<Byte>toCollection
Appends all elements to the given destination collection.
fun <C : MutableCollection<in Byte>> ByteArray.toCollection(
destination: C
): CtoKString
Decodes a string from the bytes in UTF-8 encoding in this array.
Bytes following the first occurrence of 0 byte, if it occurs, are not decoded.
fun ByteArray.toKString(): StringDecodes a string from the bytes in UTF-8 encoding in this array or its subrange.
Bytes following the first occurrence of 0 byte, if it occurs, are not decoded.
fun ByteArray.toKString(
startIndex: Int = 0,
endIndex: Int = this.size,
throwOnInvalidSequence: Boolean = false
): StringtoMutableList
Returns a MutableList filled with all elements of this array.
fun ByteArray.toMutableList(): MutableList<Byte>toMutableSet
Returns a mutable set containing all distinct elements from the given array.
fun ByteArray.toMutableSet(): MutableSet<Byte>toUByteArray
Returns an array of type UByteArray, which is a copy of this array where each element is an unsigned reinterpretation of the corresponding element of this array.
fun ByteArray.toUByteArray(): UByteArraywithIndex
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 ByteArray.withIndex(): Iterable<IndexedValue<Byte>>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.