for Each
Performs the given action on each element.
Since Kotlin
1.2Performs the given action on each entry.
Since Kotlin
1.2Performs the given action on each element.
Since Kotlin
1.3Performs the given operation on each element of this Iterator.
Since Kotlin
1.2Samples
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
}