Returns the given iterator itself. This allows to use an instance of iterator in a for
loop.
Since Kotlin
1.0Samples
import java.util.*
fun main() {
val mutableList = mutableListOf(1, 2, 3)
val mutableIterator = mutableList.iterator()
for (e in mutableIterator) {
if (e % 2 == 0) {
mutableIterator.remove()
}
println("The element is $e")
}
}
Target: JVMRunning on v.2.1.20
Returns an Iterator over the entries in the Map.
Since Kotlin
1.0Samples
import kotlin.test.*
import java.util.*
fun main() {
val map = mapOf("beverage" to 2.7, "meal" to 12.4, "dessert" to 5.8)
for ((key, value) in map) {
println("$key - $value")
}
}
Target: JVMRunning on v.2.1.20
Returns a MutableIterator over the mutable entries in the MutableMap.
Since Kotlin
1.0Creates an Iterator for an java.util.Enumeration, allowing to use it in for
loops.
Since Kotlin
1.0Samples
import java.util.*
fun main() {
val vector = Vector<String>().apply {
add("RED")
add("GREEN")
add("BLUE")
}
for (e in vector.elements()) {
println("The element is $e")
}
}
Target: JVMRunning on v.2.1.20