
In this example, we’re appending the List of elements of type Integer returned by the filterIsInstanceTo() function to the mutableList. Subsequently, we can use the filterIsInstanceTo() function to append a List of elements of a specified type to the destination List: val countr圜ode = listOf("Germany", 49, null, "India", 91, "Japan", 81, "Brazil", null, "Australia", 61)ĪssertTrue(ntainsAll(listOf(1,24,49,91,81,61))) In this case, we’re using the filterIsInstance() function to return a List of elements of type Integer. Val filterList = countr圜ode.filterIsInstance()ĪssertTrue(ntainsAll(listOf(49,91,81,61))) The filterIsInstance() function can be used to return a List of elements of a specified type: val countr圜ode = listOf("Germany", 49, null, "India", 91, "Japan", 81, "Brazil", null, "Australia", 61) In this example, the filterIndexedTo() function appends the resulting two elements matching the predicate to the mutableList. It then returns a List of elements matching the given predicate: val filterList = countries.filterIndexed )ĪssertTrue(ntainsAll(listOf("United States","Canada","Germany","Australia")))

Get started Expressive and concise Kotlin's modern language features allow you to focus on expressing your ideas and write less boilerplate code. The predicate of this function uses both the index and the element as arguments. Kotlin is a modern statically typed programming language used by over 60 of professional Android developers that helps boost productivity, developer satisfaction, and code safety.


Returns true if at least one element matches the given predicate. 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. Syntax 2 fun Iterable.any(predicate: (T) -> Boolean): Boolean

Returns true if collection has at least one element. 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.
