copyOfRange

Returns a new array which is a copy of the specified range of the original array.

Since Kotlin

1.3

Parameters

fromIndex

the start of the range (inclusive) to copy.

toIndex

the end of the range (exclusive) to copy.

Throws

if fromIndex is less than zero or toIndex is greater than the size of this array.


expect fun <T> Array<T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T>(source)
expect fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray(source)
expect fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray(source)
expect fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray(source)
expect fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray(source)
expect fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray(source)
expect fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray(source)
expect fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray(source)
expect fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray(source)

Returns a new array which is a copy of the specified range of the original array.

Since Kotlin

1.0

Parameters

fromIndex

the start of the range (inclusive) to copy.

toIndex

the end of the range (exclusive) to copy.

Throws

if fromIndex is less than zero or toIndex is greater than the size of this array.

fun <T> Array<out T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T>(source)
actual fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray(source)
actual fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray(source)
actual fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray(source)
actual fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray(source)
actual fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray(source)
actual fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray(source)
actual fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray(source)
actual fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray(source)

Returns a new array which is a copy of the specified range of the original array.

Since Kotlin

1.1

Parameters

fromIndex

the start of the range (inclusive) to copy.

toIndex

the end of the range (exclusive) to copy.

Throws

if fromIndex is less than zero or toIndex is greater than the size of this array.

@JvmName(name = "copyOfRangeInline")
actual inline fun <T> Array<T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T>(source)
@JvmName(name = "copyOfRangeInline")
actual inline fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray(source)
@JvmName(name = "copyOfRangeInline")
actual inline fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray(source)
@JvmName(name = "copyOfRangeInline")
actual inline fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray(source)
@JvmName(name = "copyOfRangeInline")
actual inline fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray(source)
@JvmName(name = "copyOfRangeInline")
actual inline fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray(source)
@JvmName(name = "copyOfRangeInline")
actual inline fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray(source)
@JvmName(name = "copyOfRangeInline")
actual inline fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray(source)
@JvmName(name = "copyOfRangeInline")
actual inline fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray(source)

Returns a new array which is a copy of the specified range of the original array.

Since Kotlin

1.0

Parameters

fromIndex

the start of the range (inclusive) to copy.

toIndex

the end of the range (exclusive) to copy.

Throws

if fromIndex is less than zero or toIndex is greater than the size of this array.

actual fun <T> Array<T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T>(source)
actual fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray(source)
actual fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray(source)
actual fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray(source)
actual fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray(source)
actual fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray(source)
actual fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray(source)
actual fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray(source)
actual fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray(source)

Returns a new array which is a copy of the specified range of the original array.

Since Kotlin

1.3

Parameters

fromIndex

the start of the range (inclusive) to copy.

toIndex

the end of the range (exclusive) to copy.

Throws

if fromIndex is less than zero or toIndex is greater than the size of this array.

actual fun <T> Array<T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T>(source)
actual fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray(source)
actual fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray(source)
actual fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray(source)
actual fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray(source)
actual fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray(source)
actual fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray(source)
actual fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray(source)
actual fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray(source)

Returns a new array which is a copy of the specified range of the original array.

Since Kotlin

1.8

Parameters

fromIndex

the start of the range (inclusive) to copy.

toIndex

the end of the range (exclusive) to copy.

Throws

if fromIndex is less than zero or toIndex is greater than the size of this array.

actual fun <T> Array<T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T>(source)
actual fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray(source)
actual fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray(source)
actual fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray(source)
actual fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray(source)
actual fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray(source)
actual fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray(source)
actual fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray(source)
actual fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray(source)

Returns a new array which is a copy of the specified range of the original array.

Since Kotlin

1.8

Parameters

fromIndex

the start of the range (inclusive) to copy.

toIndex

the end of the range (exclusive) to copy.

Throws

if fromIndex is less than zero or toIndex is greater than the size of this array.