toList

fun <T> Stream<T>.toList(): List<T>(source)

Returns a List containing all elements produced by this stream.

Since Kotlin

1.2

Samples

import java.util.stream.*
import kotlin.streams.*

fun main() { 
   //sampleStart 
   val stringStream: Stream<String> = Stream.of("Lion", "Leopard", "Jaguar", "Tiger")
val stringList: List<String> = stringStream.toList()
println(stringList) // [Lion, Leopard, Jaguar, Tiger] 
   //sampleEnd
}

Returns a List containing all elements produced by this stream.

Since Kotlin

1.2

Samples

import java.util.stream.*
import kotlin.streams.*

fun main() { 
   //sampleStart 
   val intStream: IntStream = IntStream.of(10, 20, 30)
val intList: List<Int> = intStream.toList()
println(intList) // [10, 20, 30] 
   //sampleEnd
}

Returns a List containing all elements produced by this stream.

Since Kotlin

1.2

Samples

import java.util.stream.*
import kotlin.streams.*

fun main() { 
   //sampleStart 
   val longStream: LongStream = LongStream.of(3_000_000_000, 4_000_000_000, 5_000_000_000)
val longList: List<Long> = longStream.toList()
println(longList) // [3000000000, 4000000000, 5000000000] 
   //sampleEnd
}

Returns a List containing all elements produced by this stream.

Since Kotlin

1.2

Samples

import java.util.stream.*
import kotlin.streams.*

fun main() { 
   //sampleStart 
   val doubleStream: DoubleStream = DoubleStream.of(1e2, 1e3, 1e4)
val doubleList: List<Double> = doubleStream.toList()
println(doubleList) // [100.0, 1000.0, 10000.0] 
   //sampleEnd
}