W3cubDocs

/Kotlin

elementAt

Platform and version requirements: JVM (1.0), JS (1.1), Native (1.3)
fun <T> Array<out T>.elementAt(index: Int): T
Platform and version requirements: JVM (1.0), JS (1.1), Native (1.3)
fun ByteArray.elementAt(index: Int): Byte
Platform and version requirements: JVM (1.0), JS (1.1), Native (1.3)
fun ShortArray.elementAt(index: Int): Short
Platform and version requirements: JVM (1.0), JS (1.1), Native (1.3)
fun IntArray.elementAt(index: Int): Int
Platform and version requirements: JVM (1.0), JS (1.1), Native (1.3)
fun LongArray.elementAt(index: Int): Long
Platform and version requirements: JVM (1.0), JS (1.1), Native (1.3)
fun FloatArray.elementAt(index: Int): Float
Platform and version requirements: JVM (1.0), JS (1.1), Native (1.3)
fun DoubleArray.elementAt(index: Int): Double
Platform and version requirements: JVM (1.0), JS (1.1), Native (1.3)
fun BooleanArray.elementAt(index: Int): Boolean
Platform and version requirements: JVM (1.0), JS (1.1), Native (1.3)
fun CharArray.elementAt(index: Int): Char
Platform and version requirements: JVM (1.3), JS (1.3)
@ExperimentalUnsignedTypes fun UIntArray.elementAt(
    index: Int
): UInt
Platform and version requirements: Native (1.3)
fun UIntArray.elementAt(index: Int): UInt
Platform and version requirements: JVM (1.3), JS (1.3)
@ExperimentalUnsignedTypes fun ULongArray.elementAt(
    index: Int
): ULong
Platform and version requirements: Native (1.3)
fun ULongArray.elementAt(index: Int): ULong
Platform and version requirements: JVM (1.3), JS (1.3)
@ExperimentalUnsignedTypes fun UByteArray.elementAt(
    index: Int
): UByte
Platform and version requirements: Native (1.3)
fun UByteArray.elementAt(index: Int): UByte
Platform and version requirements: JVM (1.3), JS (1.3)
@ExperimentalUnsignedTypes fun UShortArray.elementAt(
    index: Int
): UShort
Platform and version requirements: 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
}
Platform and version requirements: JVM (1.0), JS (1.0), 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
}
Platform and version requirements: JVM (1.0), JS (1.0), 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
}

© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/element-at.html