asSequence

Creates a Sequence instance that wraps the original stream iterating through its elements.

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   val stringStream: Stream<String> = Stream.of("Never", "gonna", "give", "you", "up")
val stringSequence: Sequence<String> = stringStream.asSequence()
println(stringSequence.joinToString(" ")) // Never gonna give you up 
   //sampleEnd
}

Creates a Sequence instance that wraps the original stream iterating through its elements.

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   val intStream: IntStream = IntStream.of(5, 6, 7)
val intSequence: Sequence<Int> = intStream.asSequence()
println(intSequence.joinToString(", ")) // 5, 6, 7 
   //sampleEnd
}

Creates a Sequence instance that wraps the original stream iterating through its elements.

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   val longStream: LongStream = LongStream.of(5_000_000_000, 6_000_000_000, 7_000_000_000)
val longSequence: Sequence<Long> = longStream.asSequence()
println(longSequence.joinToString(", ")) // 5000000000, 6000000000, 7000000000 
   //sampleEnd
}

Creates a Sequence instance that wraps the original stream iterating through its elements.

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   val doubleStream: DoubleStream = DoubleStream.of(1e2, 1e3, 1e4)
val doubleSequence: Sequence<Double> = doubleStream.asSequence()
println(doubleSequence.joinToString(", ")) // 100.0, 1000.0, 10000.0 
   //sampleEnd
}