W3cubDocs

/Kotlin

firstOrNull

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun <T> Array<out T>.firstOrNull(): T?
fun ByteArray.firstOrNull(): Byte?
fun ShortArray.firstOrNull(): Short?
fun IntArray.firstOrNull(): Int?
fun LongArray.firstOrNull(): Long?
fun FloatArray.firstOrNull(): Float?
fun DoubleArray.firstOrNull(): Double?
fun BooleanArray.firstOrNull(): Boolean?
fun CharArray.firstOrNull(): Char?
@ExperimentalUnsignedTypes fun UIntArray.firstOrNull(): UInt?
@ExperimentalUnsignedTypes fun ULongArray.firstOrNull(): ULong?
@ExperimentalUnsignedTypes fun UByteArray.firstOrNull(): UByte?
@ExperimentalUnsignedTypes fun UShortArray.firstOrNull(): UShort?

Returns the first element, or null if the array is empty.

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
inline fun <T> Array<out T>.firstOrNull(
    predicate: (T) -> Boolean
): T?
inline fun ByteArray.firstOrNull(
    predicate: (Byte) -> Boolean
): Byte?
inline fun ShortArray.firstOrNull(
    predicate: (Short) -> Boolean
): Short?
inline fun IntArray.firstOrNull(
    predicate: (Int) -> Boolean
): Int?
inline fun LongArray.firstOrNull(
    predicate: (Long) -> Boolean
): Long?
inline fun FloatArray.firstOrNull(
    predicate: (Float) -> Boolean
): Float?
inline fun DoubleArray.firstOrNull(
    predicate: (Double) -> Boolean
): Double?
inline fun BooleanArray.firstOrNull(
    predicate: (Boolean) -> Boolean
): Boolean?
inline fun CharArray.firstOrNull(
    predicate: (Char) -> Boolean
): Char?
inline fun <T> Iterable<T>.firstOrNull(
    predicate: (T) -> Boolean
): T?
@ExperimentalUnsignedTypes inline fun UIntArray.firstOrNull(
    predicate: (UInt) -> Boolean
): UInt?
@ExperimentalUnsignedTypes inline fun ULongArray.firstOrNull(
    predicate: (ULong) -> Boolean
): ULong?
@ExperimentalUnsignedTypes inline fun UByteArray.firstOrNull(
    predicate: (UByte) -> Boolean
): UByte?
@ExperimentalUnsignedTypes inline fun UShortArray.firstOrNull(
    predicate: (UShort) -> Boolean
): UShort?

Returns the first element matching the given predicate, or null if element was not found.

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun <T> Iterable<T>.firstOrNull(): T?

Returns the first element, or null if the collection is empty.

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun <T> List<T>.firstOrNull(): T?

Returns the first element, or null if the list is empty.

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