Kotlin – List of Strings

To define a list of Strings in Kotlin, call listOf() function and pass all the Strings as arguments to it.

The syntax of listOf() function is

fun <T> listOf(vararg elements: T): List<T>

listOf() function returns a read-only List.

Since, we are passing strings for elements parameter, listOf() function returns a List<String> object.


In the following program, we will define a list of Strings using listOf() function.


fun main(args: Array<String>) {
    val names = listOf("Abc", "Xyz", "Pqr")


[Abc, Xyz, Pqr]


In this Kotlin Tutorial, we learned how to define a list of Strings in Kotlin, using listOf() function.