Kotlin listOf() Example

The listOf() method creates a new read-only list in Kotlin. A list is a generic ordered collection of elements.

Kotlin listOf() Example

The example creates a new list of words with listOf(). The size of the list is determined with the size attribute.
package net.sourcecodeexamples.kotlin

fun main() {
    val words = listOf("Ab", "cup", "dog", "spectacles")
    println("The list contains ${words.size} elements.")
}
Output:
The list contains 4 elements.


Comments