Collections: MapList



// File:            Main.kt
// Programmer: Engineer Nolverto Urias Obeso
// Creation Date: 06/21/2023
// Email: nolvertou@gmail.com
// Description: Using MapList Collection

fun main() {
val cures: Map<String,String> = mapOf("white spots" to "Ich", "red sores" to "hole disease")


println(cures["white spots"]) // Output: Ich
println(cures.get("red sores")) // Output: hole disease
println(cures.getOrDefault("bloating", "sorry I don't know")) // Output: sorry I don't know
println(cures.getOrElse("bloating"){ "No cure for this"}) // Output: No cure for this

val inventory: MutableMap<String, Int> = mutableMapOf("fishnet" to 1)
println(inventory) // Output: {fishnet=1}
inventory.put("tank scrubber", 4)
println(inventory) // Output: {fishnet=1, tank scrubber=4}
inventory.remove("fishnet")
println(inventory) // Output: {tank scrubber=4}

}

Comments

Popular posts from this blog