forEach

inline fun <T> Iterator<T>.forEach(operation: (T) -> Unit)(source)

Performs the given operation on each element of this Iterator.

Since Kotlin

1.1

Samples

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
}
inline fun <T> Iterator<T>.forEach(operation: (T) -> Unit)(source)

Performs the given operation on each element of this Iterator.

Since Kotlin

1.0

Samples

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
}

inline fun <T> Array<out T>.forEach(action: (T) -> Unit)(source)
inline fun ByteArray.forEach(action: (Byte) -> Unit)(source)
inline fun ShortArray.forEach(action: (Short) -> Unit)(source)
inline fun IntArray.forEach(action: (Int) -> Unit)(source)
inline fun LongArray.forEach(action: (Long) -> Unit)(source)
inline fun FloatArray.forEach(action: (Float) -> Unit)(source)
inline fun DoubleArray.forEach(action: (Double) -> Unit)(source)
inline fun BooleanArray.forEach(action: (Boolean) -> Unit)(source)
inline fun CharArray.forEach(action: (Char) -> Unit)(source)
inline fun <T> Iterable<T>.forEach(action: (T) -> Unit)(source)

Performs the given action on each element.

Since Kotlin

1.0

inline fun <K, V> Map<out K, V>.forEach(action: (Map.Entry<K, V>) -> Unit)(source)

Performs the given action on each entry.

Since Kotlin

1.0