W3cubDocs

/Kotlin

toTypedArray

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun ByteArray.toTypedArray(): Array<Byte>
fun ShortArray.toTypedArray(): Array<Short>
fun IntArray.toTypedArray(): Array<Int>
fun LongArray.toTypedArray(): Array<Long>
fun FloatArray.toTypedArray(): Array<Float>
fun DoubleArray.toTypedArray(): Array<Double>
fun BooleanArray.toTypedArray(): Array<Boolean>
fun CharArray.toTypedArray(): Array<Char>

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

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
@ExperimentalUnsignedTypes fun UIntArray.toTypedArray(): Array<UInt>
@ExperimentalUnsignedTypes fun ULongArray.toTypedArray(): Array<ULong>
@ExperimentalUnsignedTypes fun UByteArray.toTypedArray(): Array<UByte>
@ExperimentalUnsignedTypes fun UShortArray.toTypedArray(): Array<UShort>

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

Platform and version requirements: JVM (1.0), Native (1.3)
fun <reified T> Collection<T>.toTypedArray(): Array<T>
Platform and version requirements: JS (1.1)
fun <T> Collection<T>.toTypedArray(): Array<T>
For JVM

Returns a typed array containing all of 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
}
For Native

Returns a typed array containing all of 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.

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/to-typed-array.html