November 2018
Intermediate to advanced
388 pages
9h 5m
English
Collections are used for storing and processing a set of objects. Kotlin provides an elegant syntax for iteration over a collection.
Consider the code for 9_IteratingOverList.kts:
val names = listOf("Mark", "Tina", "Williams")for(name in names) { println(name)}
The output is as follows:

If we are interested in getting the index value, we can do that by running the indices command on the collection.
Consider the code for 9a_IteratingOverListIndex.kts:
val names = listOf("Mark", "Tina", "Williams")for(index in names.indices) { println(index)}
The output is as follows:
As the index is a String, we can write an expression ...
Read now
Unlock full access