W3cubDocs

/Kotlin

first

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

Returns first element.

Exceptions

NoSuchElementException - if the array is empty.

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

Returns the first element matching the given predicate.

Exceptions

NoSuchElementException - if no such element is found.

fun <T> Iterable<T>.first(): T

Returns first element.

Exceptions

NoSuchElementException - if the collection is empty.

fun <T> List<T>.first(): T

Returns first element.

Exceptions

NoSuchElementException - if the list is empty.

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