forEach
Performs the given action on each element.
Since Kotlin
1.0Performs the given action on each entry.
Since Kotlin
1.0Performs the given action on each element.
Since Kotlin
1.3Performs the given operation on each element of this Iterator.
Since Kotlin
1.0Samples
import java.util.*
fun main() {
//sampleStart
val iterator = (1..3).iterator()
// skip an element
if (iterator.hasNext()) {
iterator.next()
}
// do something with the rest of elements
iterator.forEach {
println("The element is $it")
}
//sampleEnd
}