elementAt

fun <T> Sequence<T>.elementAt(index: Int): T

Returns an element at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this sequence.

The operation is terminal.

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf(1, 2, 3)
assertPrints(list.elementAt(0), "1")
assertPrints(list.elementAt(2), "3")
assertFailsWith<IndexOutOfBoundsException> { list.elementAt(3) }

val emptyList = emptyList<Int>()
assertFailsWith<IndexOutOfBoundsException> { emptyList.elementAt(0) } 
   //sampleEnd
}