Lists

The List interface represents immutable list of items. Don't confuse with Java List interface. You can create instance from any Java list class or from factory function listOf() or List(). Default implementation is ArrayList.

The MutableList interface represents mutable list of items. You can create instance from any Java list class or from factory function mutableListOf() or MutableList().

You can use operator in instead the contains() method.

You can use operator [] instead the get()/set() methods.

Property size indicates current number of items in list.

var lst = listOf("1", "2", "3")
val mutableLst = mutableListOf("1","0","2")
val lst2 : List<String> = ArrayList()

if("1" in lst){/* ... */}

println (lst[1])
        
lst.forEach{
    println ("$it ")
}

class Cls{

    private val _lst = mutableListOf("1","0","2")

    // expose _lst to user as read-only list
    val lst : List<String>
        get() = _lst
}