Created
March 14, 2020 14:22
-
-
Save magdamiu/d6567474f8e79de03fe4ed64f641e0ed to your computer and use it in GitHub Desktop.
Map and MutableMap samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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