flatten

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun <T> Array<out Array<out T>>.flatten(): List<T>

Returns a single list of all elements from all arrays in the given array.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val deepArray = arrayOf(
    arrayOf(1),
    arrayOf(2, 3),
    arrayOf(4, 5, 6)
)

println(deepArray.flatten()) // [1, 2, 3, 4, 5, 6]
//sampleEnd
}
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun <T> Iterable<Iterable<T>>.flatten(): List<T>

Returns a single list of all elements from all collections in the given collection.



fun main(args: Array<String>) {
//sampleStart
val deepList = listOf(listOf(1), listOf(2, 3), listOf(4, 5, 6))
println(deepList.flatten()) // [1, 2, 3, 4, 5, 6]
//sampleEnd
}

© 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/flatten.html