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.")
The list contains 4 elements.

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course