October 2019
Intermediate to advanced
434 pages
11h 54m
English
Beyond just functions for manipulating collections, the Kotlin standard library provides many other helpful functions. Let's explore a few examples of how these functions can make our code more concise, readable, and safe.
One such function is isNullOrEmpty(). This provides a convenient way to check whether a collection is either null or empty:
if (list.isNullOrEmpty()) { // handle empty case}
This helps us to handle those common edge cases with a standard available function.
If we find that a collection is null, but would rather work with an empty collection than a null one, the Kotlin standard library provides functions to retrieve an empty collection of your choosing:
val emptyList = emptyList<String>
Read now
Unlock full access