list Of
Returns a new read-only list of given elements. The returned list is serializable (JVM).
Samples
import samples.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf('a', 'b', 'c')
assertPrints(list.size, "3")
assertTrue(list.contains('a'))
assertPrints(list.indexOf('b'), "1")
assertPrints(list[2], "c")
//sampleEnd
}
Returns an empty read-only list. The returned list is serializable (JVM).
Samples
import samples.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf<String>()
assertTrue(list.isEmpty())
// another way to create an empty list,
// type parameter is inferred from the expected type
val other: List<Int> = emptyList()
assertTrue(list == other, "Empty lists are equal")
assertPrints(list, "[]")
assertFails { list[0] }
//sampleEnd
}