Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created March 14, 2020 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magdamiu/d6567474f8e79de03fe4ed64f641e0ed to your computer and use it in GitHub Desktop.
Save magdamiu/d6567474f8e79de03fe4ed64f641e0ed to your computer and use it in GitHub Desktop.
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