Monday 25 September 2017

Iterate Over Lists in Kotlin

Create a list, add, remove and then iterate over a list.

fun main(args: Array<String>) {
    var list = mutableListOf<String>("zero", "one", "two", "three", "four")

    list.add("five")
    list.remove("zero")

    for(str in list) {
        println("value = " + str)
    }
}


This has the following output

value = one
value = two
value = three
value = four
value = five

No comments:

Post a Comment