get

open operator override fun get(index: Int): E(source)

Returns the element at the specified index in the list.

Since Kotlin

1.4

Throws

if index is less than zero or greater than or equal to size of this list.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf(1, 2, 3)

assertEquals(1, list[0])
assertEquals(3, list[2])
// list[3] // will fail with IndexOutOfBoundsException 
   //sampleEnd
}