

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.

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