-
Notifications
You must be signed in to change notification settings - Fork 22
Kotlin basics : Using Map in the code
Devrath edited this page Dec 24, 2023
·
1 revision
- A
Map
is a part of a collection framework where you provide akey
as an input and you get a correspondingvalue
as an output. -
Map
is also called a dictionary.
-
Map
- > This is used when we have a fixed set of elements and it won't modify at runtime. -
MutableMap
-> We use this when the collection has to be modified at runtime - If you try to fetch a value for a key where the key does not exist, we get a null reply
private fun initiate() {
val listOfCities = mapOf(
1 to "Bangalore",
2 to "Mumbai",
3 to "Chennai",
)
println(listOfCities[1])
val listOfNames = mutableMapOf(
1 to "Manish",
2 to "John",
3 to "Sam",
)
listOfNames[4] = "Anudeep"
println(listOfNames[4])
}
}