to List
Платформы и требования к версии: Common (1.0)
fun <T> Array<out T>.toList(): List<T>
fun ByteArray.toList(): List<Byte>
fun ShortArray.toList(): List<Short>
fun IntArray.toList(): List<Int>
fun LongArray.toList(): List<Long>
fun FloatArray.toList(): List<Float>
fun DoubleArray.toList(): List<Double>
fun BooleanArray.toList(): List<Boolean>
fun CharArray.toList(): List<Char>
fun <T> Iterable<T>.toList(): List<T>
Возвращает List, содержащий все элементы.
fun <K, V> Map<out K, V>.toList(): List<Pair<K, V>>
Возвращает List, содержащий все пары ключ-значение.
Платформы и требования к версии: JVM (1.0)
inline fun <T> Enumeration<T>.toList(): List<T>
Возвращает список, содержащий элементы, возвращённые этой перечисляемой последовательностью, в том порядке, в котором они были возвращены.
Примеры
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val numbers = java.util.Hashtable<String, Int>()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.put("three", 3)
// when you have an Enumeration from some old code
val enumeration: java.util.Enumeration<Int> = numbers.elements()
// you can convert it to list and transform further with list operations
val list = enumeration.toList().sorted()
println(list) // [1, 2, 3]
//sampleEnd
}
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/to-list.html