elementAt
fun ByteArray.elementAt(index: Int): Bytefun ShortArray.elementAt(index: Int): Shortfun IntArray.elementAt(index: Int): Intfun LongArray.elementAt(index: Int): Longfun FloatArray.elementAt(index: Int): Floatfun DoubleArray.elementAt(index: Int): Doublefun BooleanArray.elementAt(index: Int): Booleanfun CharArray.elementAt(index: Int): Char@ExperimentalUnsignedTypes fun ULongArray.elementAt(
index: Int
): ULong@ExperimentalUnsignedTypes fun UByteArray.elementAt(
index: Int
): UByte@ExperimentalUnsignedTypes fun UShortArray.elementAt(
index: Int
): UShortReturns 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
}fun <T> Iterable<T>.elementAt(index: Int): TReturns 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
}fun <T> List<T>.elementAt(index: Int): TReturns 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
}