Kotlin HashSet single()
Syntax & Examples


Syntax of HashSet.single()

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

1.
fun <T> Iterable<T>.single(): T

This extension function returns the single element, or throws an exception if the collection is empty or has more than one element.

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

This extension function returns the single element matching the given predicate, or throws exception if there is no or more than one matching element.