Kotlin List.size – Examples

Kotlin List.size

The Kotlin List.size property returns the size of the list.

Syntax

List.size

Example 1: Get the size of given list

In this example, we find the size of a given list of strings.

  1. Given list with some values in list1.
  2. Get the size of the list using size property on the list.
  3. You may print the list size to output.

Program

fun main(args: Array<String>) {
    val list1 = listOf("a", "p", "p", "l", "e")
    val listSize = list1.size
    print(listSize)
}

Output

5