If any the elements of list matches the predicate, we should get true as return value from any().Call List.any() with predicate passed as argument.Define a predicate that the number should be even.Returns true if at least one element matches the given predicate. Examples In the following example, we have a list of strings. Syntax The syntax of List.find () function is fun List.find (predicate: (T) -> Boolean): T where T can be any builtin datatype or user-defined datatype. Syntax 2 fun Iterable.any(predicate: (T) -> Boolean): Boolean An example of a list is a telephone number: its a group of digits, their order is important, and they can repeat. For other List implementations, which have not got any convenience functions, they can be initialized as, for example, val list LinkedList (). Hereâs an example: Kotlin val numbers listOf (1, 2, 3, 4, 5) In this example, we create a new list called numbers using the listOf () function. The Kotlin List.find () function is used to get the first element from the List that matches the given predicate.Returns true if collection has at least one element. 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. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |