vurchain.blogg.se

Kotlin any
Kotlin any










  • How to Filter Odd Numbers of a Kotlin List?.
  • How to Filter List of Strings based on Length in Kotlin?.
  • How to Filter Even Numbers of a Kotlin List?.
  • How to Filter Elements of a List based on Condition in Kotlin?.
  • In this Kotlin Tutorial, we learned how to check if at least one of the elements in this list matches the given predicate, using Kotlin List.any() function. Output Does list1 have at least one element? trueĭoes list2 have at least one element? false Conclusion Println("Does list2 have at least one element? $anyInList2")

    kotlin any

    Println("Does list1 have at least one element? $anyInList1") We will call list.any() function on these lists, and observe the output in the two scenarios. In this example, we will take two lists: list1 with two elements, and list2 with no elements. Output Does at least one element in list matches predicate? true Example 2: Check if List has At least One Element Println("Does at least one element in list matches predicate? $anyElementMatchesPredicate") Val anyElementMatchesPredicate = list1.any(predicate) In this example, we will take a list of elements, of type string, and check if at least one of the elements matches the given predicate that the length of string is 3. list.any() Example 1: Check if At least one element of List matches Predicate If no argument is given to any() function, then it returns true if collection has at least one element. The function returns true if at least one element matches the given predicate.

    kotlin any

    The syntax of List.any() function with a predicate passed to it is list.any(predicate)












    Kotlin any