Stream.asSequence所在位置是kotlin.streams / java.util.stream.Stream.asSequence,其相关用法介绍如下。

用法:

fun <T> Stream<T>.asSequence(): Sequence<T>

创建一个 Sequence 实例,该实例包装了遍历其元素的原始流。

例子:

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

fun main(args: Array<String>) {
//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
}

输出:

Never gonna give you up