kota's memex

Lists store items in the order that they are added, and allow for duplicate items.

To create a read-only list List, use the listOf() function. To create a mutable list MutableList, use the mutableListOf() function.

// Read only list
val readOnlyShapes = listOf("triangle", "square", "circle")
println(readOnlyShapes)
// [triangle, square, circle]

// Mutable list with explicit type declaration
val shapes: MutableList<String> = mutableListOf("triangle", "square", "circle")
println(shapes)
// [triangle, square, circle]

To prevent unwanted modifications, you can obtain read-only views of mutable lists by assigning them to a List:

val shapes: MutableList<String> = mutableListOf("triangle", "square", "circle")
val shapesLocked: List<String> = shapes