Java – kotlin stream Peek (…) method
•
Java
Java. In kotlin util. stream. Stream<> . What is the best choice for Peek (...)?
https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#peek -java. util. function. Consumer-
There seems to be no alternative intermediate operation:
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.streams/index.html
I found that only termination foreach (...)
Solution
Kotlin's stream substitute is @ L_ 403_ 3@.
listOf(1,2,3,4,5) .asSequence() .filter { it < 3 } .onEach { println("filtered $it") } .map { it * 10 } .forEach { println("final: $it") }
This is what oneach has to do
Interesting fact: kotlin wanted to call their sequence "streams" before it was obvious that Java would do the same, so they renamed it "sequences"
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码