Spec-Zone.ru › Kotlin 2

toList

kotlin-stdlib/kotlin/toList

Начиная с Kotlin: 1.0

fun <T> Pair<T, T>.toList(): List<T>

Преобразует эту пару в список.

Примеры

import kotlin.test.*

fun main() { 
   //sampleStart 
   val mixedList: List<Any> = Pair(1, "a").toList()
println(mixedList) // [1, a]
println("mixedList[0] is Int is ${mixedList[0] is Int}") // true
println("mixedList[1] is String is ${mixedList[1] is String}") // true

val intList: List<Int> = Pair(0, 1).toList()
println(intList) // [0, 1] 
   //sampleEnd
}

fun <T> Triple<T, T, T>.toList(): List<T>

Преобразует эту тройку в список.

Примеры

import kotlin.test.*

fun main() { 
   //sampleStart 
   val mixedList: List<Any> = Triple(1, "a", 0.5).toList()
println(mixedList) // [1, a, 0.5]
println("mixedList[0] is Int is ${mixedList[0] is Int}") // true
println("mixedList[1] is String is ${mixedList[1] is String}") // true
println("mixedList[2] is Double is ${mixedList[2] is Double}") // true

val intList: List<Int> = Triple(0, 1, 2).toList()
println(intList) // [0, 1, 2] 
   //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/to-list.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API