Retrieve keys / values

fun sampleCodeForMapOperator() {
    val numbersMap = mapOf("one" to 1, "two" to 2, "three" to 3)
    println(numbersMap.get("one"))
    println(numbersMap["one"])
    println(numbersMap.getOrElse("four", { getSomethingInt() }))
    println(numbersMap.getOrDefault("four", 10))
    println(numbersMap["five"])               // null
    //numbersMap.getValue("six")      // exception!
}

fun getSomethingInt(): Int {
    return 100
}
val numbersMap = mapOf("one" to 1, "two" to 2, "three" to 3)
println(numbersMap.keys)
println(numbersMap.values)

Filter

fun sampleCodeForFilterForMap() {
    val numbersMap = mapOf("key1" to 1, "key2" to 2, "key3" to 3, "key11" to 11)
    val filteredMap = numbersMap.filter { (key, value) -> key.endsWith("1") && value > 10}
    println(filteredMap)

    val numbersMapForOneProperty = mapOf("key1" to 1, "key2" to 2, "key3" to 3, "key11" to 11)
    val filteredKeysMap = numbersMapForOneProperty.filterKeys { it.endsWith("1") }
    val filteredValuesMap = numbersMapForOneProperty.filterValues { it < 10 }

    println(filteredKeysMap)
    println(filteredValuesMap)
}

Plus / Minus operators

Map write operations