elementAt

Common
JVM
JS
Native
1.0
fun <T> Array<out T>.elementAt(index: Int): T
Common
JVM
JS
Native
1.0
fun ByteArray.elementAt(index: Int): Byte
Common
JVM
JS
Native
1.0
fun ShortArray.elementAt(index: Int): Short
Common
JVM
JS
Native
1.0
fun IntArray.elementAt(index: Int): Int
Common
JVM
JS
Native
1.0
fun LongArray.elementAt(index: Int): Long
Common
JVM
JS
Native
1.0
fun FloatArray.elementAt(index: Int): Float
Common
JVM
JS
Native
1.0
fun DoubleArray.elementAt(index: Int): Double
Common
JVM
JS
Native
1.0
fun BooleanArray.elementAt(index: Int): Boolean
Common
JVM
JS
Native
1.0
fun CharArray.elementAt(index: Int): Char
Common
JVM
JS
1.3
@ExperimentalUnsignedTypes fun UIntArray.elementAt(
    index: Int
): UInt
Native
1.3
fun UIntArray.elementAt(index: Int): UInt
Common
JVM
JS
1.3
@ExperimentalUnsignedTypes fun ULongArray.elementAt(
    index: Int
): ULong
Native
1.3
fun ULongArray.elementAt(index: Int): ULong
Common
JVM
JS
1.3
@ExperimentalUnsignedTypes fun UByteArray.elementAt(
    index: Int
): UByte
Native
1.3
fun UByteArray.elementAt(index: Int): UByte
Common
JVM
JS
1.3
@ExperimentalUnsignedTypes fun UShortArray.elementAt(
    index: Int
): UShort
Native
1.3
fun UShortArray.elementAt(index: Int): UShort

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

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val list = listOf(1, 2, 3)
println(list.elementAt(0)) // 1
println(list.elementAt(2)) // 3
// list.elementAt(3) // will fail with IndexOutOfBoundsException

val emptyList = emptyList<Int>()
// emptyList.elementAt(0) // will fail with IndexOutOfBoundsException
//sampleEnd
}
Common
JVM
JS
Native
1.0
fun <T> Iterable<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 collection.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val list = listOf(1, 2, 3)
println(list.elementAt(0)) // 1
println(list.elementAt(2)) // 3
// list.elementAt(3) // will fail with IndexOutOfBoundsException

val emptyList = emptyList<Int>()
// emptyList.elementAt(0) // will fail with IndexOutOfBoundsException
//sampleEnd
}
Common
JVM
JS
Native
1.0
fun <T> List<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 list.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val list = listOf(1, 2, 3)
println(list.elementAt(0)) // 1
println(list.elementAt(2)) // 3
// list.elementAt(3) // will fail with IndexOutOfBoundsException

val emptyList = emptyList<Int>()
// emptyList.elementAt(0) // will fail with IndexOutOfBoundsException
//sampleEnd
}