From the course: Intermediate Kotlin for Android Developers

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Nullability and collections

Nullability and collections

From the course: Intermediate Kotlin for Android Developers

Start my 1-month free trial

Nullability and collections

- [Narrator] Let's take a look at how Kotlin handles nullability when it comes to collections. For this, we're going to work with the nullability and collections file in the test folder. We're going to start with our first method, list cannot be null, and we'll come here on line nine and we're going to create a variable called flavors. And this is going to contain a list of strings, and we'll use the list of function in order to populate it. And our flavors are going to be vanilla, and then strawberry. Okay, and on line 11 what we want to do is take our list and just go ahead and print it out. So we'll use for each and then print each element on it's own separate line. So let's go ahead and run this function, and make sure that we get all of our items. And there you have it, vanilla and strawberry. So let's try to change our list to be null. So we'll come here on line 10, and we'll take our flavors variable and set that equal to null. Just add another line here. And notice that we get…

Contents