getOrNull

Common
JVM
JS
Native
1.0
fun < T > Array < out T > . getOrNull ( index : Int ) : T ?
(source)
fun ByteArray . getOrNull ( index : Int ) : Byte ?
(source)
fun ShortArray . getOrNull ( index : Int ) : Short ?
(source)
fun IntArray . getOrNull ( index : Int ) : Int ?
(source)
fun LongArray . getOrNull ( index : Int ) : Long ?
(source)
fun FloatArray . getOrNull ( index : Int ) : Float ?
(source)
fun DoubleArray . getOrNull ( index : Int ) : Double ?
(source)
fun BooleanArray . getOrNull ( index : Int ) : Boolean ?
(source)
fun CharArray . getOrNull ( index : Int ) : Char ?
(source)
@ExperimentalUnsignedTypes fun UIntArray . getOrNull (
index : Int
) : UInt ?

(source)
@ExperimentalUnsignedTypes fun ULongArray . getOrNull (
index : Int
) : ULong ?

(source)
@ExperimentalUnsignedTypes fun UByteArray . getOrNull (
index : Int
) : UByte ?

(source)
@ExperimentalUnsignedTypes fun UShortArray . getOrNull (
index : Int
) : UShort ?

(source)

Returns an element at the given index or null 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.getOrNull(0)) // 1
println(list.getOrNull(2)) // 3
println(list.getOrNull(3)) // null

val emptyList = emptyList<Int>()
println(emptyList.getOrNull(0)) // null
//sampleEnd
}
Common
JVM
JS
Native
1.0
fun < T > List < T > . getOrNull ( index : Int ) : T ?
(source)

Returns an element at the given index or null 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.getOrNull(0)) // 1
println(list.getOrNull(2)) // 3
println(list.getOrNull(3)) // null

val emptyList = emptyList<Int>()
println(emptyList.getOrNull(0)) // null
//sampleEnd
}