W3cubDocs

/Kotlin

first

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

Returns first element.

Exceptions

NoSuchElementException - if the array is empty.

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

Returns the first element matching the given predicate.

Exceptions

NoSuchElementException - if no such element is found.

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

Returns first element.

Exceptions

NoSuchElementException - if the collection is empty.

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

Returns first element.

Exceptions

NoSuchElementException - 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.html