Kotlin List
$count++; if($count == 1) { include "../mobilemenu.php"; } if ($count == 2) { include "../sharemediasubfolder.php"; } ?>
List collection in Kotlin stores a list of ordered elements.
It can also store duplicate values. List is an interface in Kotlin, so it is implemented by specific implementations.
Syntax of list in Kotlin
val varname = listOf(comma separated list items)
Initiating a List
We can initiate a List using listOf helper function. In the following example, we initiated a list of Planets.
fun main(args: Array<String>)
{
var listOfPlanets = listOf("Mercury", "Venus", "Earth")
println(listOfPlanets)
}
Output:
[Mercury, Venus, Earth]
We can iterate a list using for each loop. In the following example, we are iterating through the list of planets and printing each planet.
fun main(args: Array<String>)
{
var listOfPlanets = listOf("Mercury", "Venus", "Earth")
for(planet in listOfPlanets)
{
println(planet)
}
}
Output:
Mercury
Venus
Earth