Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Map and MutableMap samples
// immutable map and mutable map
val desserts = hashMapOf("whipped cream" to "cake", "chocolate" to "cookie")
println(desserts["chocolate"])
if( desserts.isNotEmpty()) {
println("desserts size is ${desserts.size}" )
}
// contains key
println(desserts.containsKey("chocolate")) //true
// contains value
println(desserts.containsValue("cake")) //true
// contains key
println(desserts.contains("chocolate")) //true
println("chocolate" in desserts) //true
val inventory = mutableMapOf("pancake" to 1)
inventory.put("cake", 3)
inventory.remove("pancake")
if( inventory.isNotEmpty()) {
println("inventory size is ${inventory.size}" )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment