‫Welcome back.
‫In this video we're going to learn about mutable maps.
‫A mutable map is a collection that allows you to add, remove, and update key value pairs after it's
‫created.
‫Mutable maps are used to store and manage key value associations and are part of Kotlin's collection
‫framework.
‫I'll start with val vegetables price equals to mutable map of and here I'll start with potato two operator
‫and the price is $1.5.
‫I'll use another element.
‫And by the way, you separate elements by comma.
‫Tomato 23.5.
‫Broccoli 26. $0.
‫The mutable map of function is used to create a mutable map.
‫In Kotlin, you can modify a mutable map using various functions and operations such as put, remove,
‫and updating the values associated with a key.
‫For example, if I want to update the price of tomato, I specify vegetable price, which is the map.
‫Inside an angled brackets, I specify the key which is tomato and by the way, it's case sensitive,
‫so you should specify the key as it equals to for example $4.
‫So we use the square brackets to access the value associated with the key tomato and update it to the
‫new price, which is $4.
‫I can add a new element by using the put function.
‫We need to specify a key which is of type string garlic and the value which is of type double.
‫And instead of using two, we need to replace it with this comma, because this is the key and this
‫is the value.
‫And if you hover on the put function, you can see the key value pair are separated with comma.
‫Mutable maps provide flexibility when you need to work with a dynamic set of key value associations.
‫As you can change the map's contents as your program runs.
‫You can also perform map operations like key lookup, iteration, and key value pair manipulation,
‫and to print all map elements.
‫I'll use a for loop for this job for and.
‫Here I need to specify key value pair in vegetables price I need to print ln the key and the value.
‫So here the vegetable key and the price which is the value.
‫The key value in each of the vegetables price elements.
‫I need to print the key and I need to print the value.
‫You can print the key loan.
‫You can print the value alone, but in this case I am printing the key value pairs.
‫The vegetable potato 1.5 tomato for broccoli and the garlic, which we added before.
‫Okay, this is how we use mutable maps in Kotlin.
‫And this is how we work with maps in Kotlin.