Kotlin HashSet firstOrNull()
Syntax & Examples


Syntax of HashSet.firstOrNull()

There are 2 variations for the syntax of HashSet.firstOrNull() extension function. They are:

1.
fun <T> Iterable<T>.firstOrNull(): T?

This extension function returns the first element, or null if the collection is empty.

2.
fun <T> Iterable<T>.firstOrNull( predicate: (T) -> Boolean ): T?

This extension function returns the first element matching the given predicate, or null if element was not found.