toTypedArray

Common
JVM
JS
Native
1.0

Returns a typed object array containing all of the elements of this primitive array.

Common
JVM
JS
Native
1.3
@ExperimentalUnsignedTypes fun UIntArray.toTypedArray(): Array<UInt>
(source)
@ExperimentalUnsignedTypes fun ULongArray.toTypedArray(): Array<ULong>
(source)
@ExperimentalUnsignedTypes fun UByteArray.toTypedArray(): Array<UByte>
(source)
@ExperimentalUnsignedTypes fun UShortArray.toTypedArray(): Array<UShort>
(source)

Returns a typed object array containing all of the elements of this primitive array.

Common
JVM
Native
1.0
fun <reified T> Collection<T>.toTypedArray(): Array<T>
(Common source) (JVM source) (Native source)
JS
1.1
fun <T> Collection<T>.toTypedArray(): Array<T>
(source)

Returns a typed array containing all the elements of this collection.

Allocates an array of runtime type T having its size equal to the size of this collection and populates the array with the elements of this collection.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val collection = listOf(1, 2, 3)
val array = collection.toTypedArray()
println(array.contentToString()) // [1, 2, 3]
//sampleEnd
}