Mutable list: MutableList can be modified after you create it, meaning you can add, remove, or update its elements.Read-only list: List cannot be modified after you create it.
But what if you want to store more than one value? That is where having a List data type is useful.Ī list is a collection of items with a specific order. They allow you to store a certain type of value within a variable. In earlier codelabs, you learned about basic data types in Kotlin such as Int, Double, Boolean, and String. A computer with an internet connection to access the Kotlin Playground.Your program will be able to create an order, add noodles and vegetables to it, and then calculate the total cost of the order.You will create a food ordering program that uses lists in the Kotlin Playground.You will experiment with lists and list operations in the Kotlin Playground.How to iterate over all items of a list and perform an action on each item.The difference between the List and MutableList, and when to use each one.Able to create subclasses and understand how they inherit from each other.Able to define a Kotlin class, create an object instance from it, and access its properties and methods.Familiar with basic Kotlin programming concepts from Unit 1 of the Android Basics in Kotlin course: the main() function, functions arguments and return values, variables, data types and operations, as well as control flow statements.Familiar with using the Kotlin Playground for creating and editing Kotlin programs.In this codelab, you will use the Kotlin Playground to become familiar with lists in Kotlin and create a program for ordering different variations of noodle soup.
Learning how to create and use lists is an important programming concept to add to your toolbox, and it will enable you to create more sophisticated apps.
For example, there could be a list of news articles, songs, calendar events, or social media posts within an app. In programming, lists are also very useful. For some simple actions you can use the safe call operator, assuming the action also respects not operating on an empty list (to handle your case of both null and empty: myList?.It's common to make lists for all sorts of situations in your everyday life such as a list of things to do, a list of guests for an event, a wish list, or a grocery list.