withIndex
Returns a lazy Iterable that wraps each element of the original array into an IndexedValue containing the index of that element and the element itself.
Since Kotlin
1.0Returns a lazy Iterable that wraps each element of the original collection into an IndexedValue containing the index of that element and the element itself.
Since Kotlin
1.0Returns an Iterator that wraps each element produced by the original iterator into an IndexedValue containing the index of that element and the element itself.
Since Kotlin
1.0Samples
import java.util.*
fun main() {
//sampleStart
val iterator = ('a'..'c').iterator()
for ((index, value) in iterator.withIndex()) {
println("The element at $index is $value")
}
//sampleEnd
}