Syntax

Kotlin Create a List Syntax

In Kotlin, create a list: creates read-only or mutable lists — val nums = listOf(1, 2, 3) val items = mutableListOf<String>()

Quick Answer

Syntax
val nums = listOf(1, 2, 3) val items = mutableListOf<String>()
KotlinSyntax

Create a List

Code example
val nums = listOf(1, 2, 3) val items = mutableListOf<String>()

Creates read-only or mutable lists.

Learn More

How to create a list in Kotlin

  1. Open your Kotlin file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Kotlin Create a List Syntax

Use val nums = listOf(1, 2, 3) val items = mutableListOf<String>().

Related Syntax References

Frequently asked questions

What is the Kotlin syntax for create a list?

Use this pattern: val nums = listOf(1, 2, 3) val items = mutableListOf<String>()

Can I copy this Kotlin code example?

Yes. Use Copy code and adapt the example to your program.

Is this Kotlin syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify