Kotlin set
$count++; if($count == 1) { include "../mobilemenu.php"; } if ($count == 2) { include "../sharemediasubfolder.php"; } ?>
Set in Kotlin stores a list of elements.
However unlike a list, set can only have unique values.
Syntax of set in Kotlin
var varname = setOf(comma separate set element)
Initializing a set in Kotlin
In the following example, we are creating a set of fruits. We used the helper function setOf.
fun main(args: Array<String>)
{
var setOfFruits = setOf("Apple", "Pineapple", "Grapes")
println(setOfFruits)
}
Output:
[Apple, Pineapple, Grapes]
Iterating a Set
We can iterate a set using for each loop. In the following example, we are iterating through the set of fruits and printing each fruit.
fun main(args: Array<String>)
{
var setOfFruits = setOf("Apple", "Pineapple", "Grapes")
for(fruit in setOfFruits)
{
println(fruit)
}
}
Output:
Apple
Pineapple
Grapes