opkcooking.blogg.se

Kotlin list any example
Kotlin list any example






kotlin list any example

If any the elements of list matches the predicate, we should get true as return value from any().

kotlin list any example

  • Call List.any() with predicate passed as argument.
  • Happily, Kotlin can infer the generic type from the parameter type so we can.

    • Define a predicate that the number should be even. We can create an instance of such a class by setting a parameterized type explicitly when using the constructor: val parameterizedClass ParameterizedClass < String > ( 'string-value' ) val res parameterizedClass.getValue () assertTrue (res is String) Copy.

    Returns true if at least one element matches the given predicate. Syntax 2 fun Iterable.any(predicate: (T) -> Boolean): Boolean List It is an ordered collection in which we can access elements or items by using indices integer numbers that define a position for each element. Indices start from zero the index of the first element and go to. Returns true if collection has at least one element. Kotlin List stores elements in a specified order and provides indexed access to them. The Kotlin List.any() function can be used to check if the list has at least one element, or if the list has at least one element that matches the given predicate. Any is a function that is added as an extension to Iterable and Map interfaces, which take a higher-order function as param to predicate the condition and.








    Kotlin list any example