DEV Community

loizenai
loizenai

Posted on

Kotlin methods – any(), none(), all(), contains() example

Kotlin methods – any(), none(), all(), contains() example

https://grokonez.com/kotlin/kotlin-methods-none-contains

In the tutorial, Grokonez will show you how to work with some Kotlin methods: any(), all(), none(), contains().

I. Kotlin methods - any(), none(), all(), contains()

1. any() vs none() methods

Kotlin has 2 signatures for any() method:


// 1. returns 'true' if collection has at least one element.
public fun  Iterable.any(): Boolean

// 2. returns `true` if at least one element matches the given [predicate].
public inline fun  Iterable.any(predicate: (T) -> Boolean): Boolean

none() method is the opposite of any() method. none() method has 2 signatures:


// 1. returns 'true' if the collection has no elements.
public fun  Iterable.none(): Boolean

// 2. returns 'true' if no elements match the given [predicate].
public inline fun  Iterable.none(predicate: (T) -> Boolean): Boolean

Practice:

More at:

https://grokonez.com/kotlin/kotlin-methods-none-contains

Top comments (0)