October 2018
Intermediate to advanced
370 pages
9h 15m
English
This function allows us to filter out elements of specific types. We can create a list of different elements and call the filterIsInstance<type> function by explicitly defining a data type that we want to filter out. Take a look at the following example:
val list = listOf("One", 2.0, 3, null, "Four", 5)val stringList = list.filterIsInstance<String>()println("Filter string elements")println(stringList)val intList = list.filterIsInstance<Int>()println("Filter int elements")println(intList)
The filterIsInstance<String> function will return a list of String elements, while filterIsInstance<Int> will return a list of Int elements.
Read now
Unlock full access