ByteArray

class ByteArray(size: Int)(source)

An array of bytes. When targeting the JVM, instances of this class are represented as byte[].

Since Kotlin

1.0
class ByteArray(size: Int)(source)

An array of bytes. When targeting the JVM, instances of this class are represented as byte[].

Since Kotlin

1.1

Constructors

Link copied to clipboard
fun ByteArray(size: Int, init: (Int) -> Byte)

Creates a new array of the specified size, where each element is calculated by calling the specified init function.

fun ByteArray(size: Int, init: (Int) -> Byte)

Creates a new array of the specified size, where each element is calculated by calling the specified init function.

Link copied to clipboard
fun ByteArray(size: Int)

Creates a new array of the specified size, with all elements initialized to zero.

fun ByteArray(size: Int)

Creates a new array of the specified size, with all elements initialized to zero.

Functions

Link copied to clipboard
operator fun get(index: Int): Byte

Returns the array element at the given index. This method can be called using the index operator.

Since Kotlin 1.0
operator fun get(index: Int): Byte

Returns the array element at the given index. This method can be called using the index operator.

Since Kotlin 1.1
Link copied to clipboard
operator fun iterator(): ByteIterator

Creates an iterator over the elements of the array.

Since Kotlin 1.0
operator fun iterator(): ByteIterator

Creates an iterator over the elements of the array.

Since Kotlin 1.1
Link copied to clipboard
operator fun set(index: Int, value: Byte)

Sets the element at the given index to the given value. This method can be called using the index operator.

Since Kotlin 1.0
operator fun set(index: Int, value: Byte)

Sets the element at the given index to the given value. This method can be called using the index operator.

Since Kotlin 1.1

Properties

Link copied to clipboard
val size: Int

Returns the number of elements in the array.

Since Kotlin 1.0
val size: Int

Returns the number of elements in the array.

Since Kotlin 1.1

Extensions

Link copied to clipboard
fun ByteArray.binarySearch(element: Byte, fromIndex: Int = 0, toIndex: Int = size): Int
fun ByteArray.binarySearch(element: Byte, fromIndex: Int = 0, toIndex: Int = size): Int

Searches the array or the range of the array for the provided element using the binary search algorithm. The array is expected to be sorted, otherwise the result is undefined.

Since Kotlin 1.0
Link copied to clipboard

Creates an input stream for reading data from this byte array.

Since Kotlin 1.0
inline fun ByteArray.inputStream(offset: Int, length: Int): ByteArrayInputStream
inline fun ByteArray.inputStream(offset: Int, length: Int): ByteArrayInputStream

Creates an input stream for reading data from the specified portion of this byte array.

Since Kotlin 1.0
Link copied to clipboard
Since Kotlin 1.0
Link copied to clipboard
inline fun <R : Comparable<R>> ByteArray.maxBy(selector: (Byte) -> R): Byte?
inline fun <R : Comparable<R>> ByteArray.maxBy(selector: (Byte) -> R): Byte?
Since Kotlin 1.0
Link copied to clipboard
fun ByteArray.maxWith(comparator: Comparator<in Byte>): Byte?
fun ByteArray.maxWith(comparator: Comparator<in Byte>): Byte?
Since Kotlin 1.0
Link copied to clipboard
Since Kotlin 1.0
Link copied to clipboard
inline fun <R : Comparable<R>> ByteArray.minBy(selector: (Byte) -> R): Byte?
inline fun <R : Comparable<R>> ByteArray.minBy(selector: (Byte) -> R): Byte?
Since Kotlin 1.0
Link copied to clipboard
fun ByteArray.minWith(comparator: Comparator<in Byte>): Byte?
fun ByteArray.minWith(comparator: Comparator<in Byte>): Byte?
Since Kotlin 1.0
Link copied to clipboard
inline fun ByteArray.sort(noinline comparison: (a: Byte, b: Byte) -> Int)
inline fun ByteArray.sort(noinline comparison: (a: Byte, b: Byte) -> Int)

Sorts the array in-place according to the order specified by the given comparison function.

Since Kotlin 1.1
Link copied to clipboard

Returns a new SortedSet of all elements.

Since Kotlin 1.0
Link copied to clipboard
inline fun ByteArray.toString(charset: Charset): String
inline fun ByteArray.toString(charset: Charset): String

Converts the contents of this byte array to a string using the specified charset.

Since Kotlin 1.0