From the course: Android Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Manage data collections in Kotlin

Manage data collections in Kotlin - Android Tutorial

From the course: Android Development Tips

Manage data collections in Kotlin

- [Instructor] Kotlin has a powerful set of interfaces that let you manage dynamic data collections. These are categorized as lists, sets, and maps. These interfaces are part of the Kotlin.collections package and can be used without any import statements. In this tip, I'm going to create a shopping cart collection. It'll be a list, an ordered set of data. Each item in the list will contain an instance of a clothing item and a quantity. The items priced will be part of a ClothingItem object. And then I'll be able to loop through the collection and get a total value. I already have one model class that I've named ClothingItem. And as I showed in another tip, it's a sealed class. ClothingItem is the super class and it has sub-classes named Shirt and Pants. When I create instances of this class, I have to use the sub-classes. The sealed class is abstract. I'll need another data class for my shopping cart and this new class will keep track of a single line item. I'll put it in my model…

Contents