singleOrNull

fun <T> Array<out T>.singleOrNull(): T?(source)

Returns single element, or null if the array is empty or has more than one element.

Since Kotlin

1.0

inline fun <T> Array<out T>.singleOrNull(predicate: (T) -> Boolean): T?(source)
inline fun ByteArray.singleOrNull(predicate: (Byte) -> Boolean): Byte?(source)
inline fun ShortArray.singleOrNull(predicate: (Short) -> Boolean): Short?(source)
inline fun IntArray.singleOrNull(predicate: (Int) -> Boolean): Int?(source)
inline fun LongArray.singleOrNull(predicate: (Long) -> Boolean): Long?(source)
inline fun FloatArray.singleOrNull(predicate: (Float) -> Boolean): Float?(source)
inline fun DoubleArray.singleOrNull(predicate: (Double) -> Boolean): Double?(source)
inline fun BooleanArray.singleOrNull(predicate: (Boolean) -> Boolean): Boolean?(source)
inline fun CharArray.singleOrNull(predicate: (Char) -> Boolean): Char?(source)
inline fun <T> Iterable<T>.singleOrNull(predicate: (T) -> Boolean): T?(source)

Returns the single element matching the given predicate, or null if element was not found or more than one element was found.

Since Kotlin

1.0

Returns single element, or null if the collection is empty or has more than one element.

Since Kotlin

1.0

fun <T> List<T>.singleOrNull(): T?(source)

Returns single element, or null if the list is empty or has more than one element.

Since Kotlin

1.0

Returns single element, or null if the array is empty or has more than one element.

Since Kotlin

1.3

Returns the single element matching the given predicate, or null if element was not found or more than one element was found.

Since Kotlin

1.3