SingleOrNull

This function does the same job as the single, but instead of throwing an exception returns null if no or more than 1 item matches the predicate.

val numbers = listOf(1, 2, 3, 4, 5)
val smallerThan1 = numbers.singleOrNull { n -> n < 1 }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.48.218