https://kotlinlang.org logo
i

ilya.gorbunov

05/31/2016, 1:44 AM
@aamit01: Nothing ready at the moment in the standard library, but we're considering to add a function like this. Meanwhile, you can also try something like
Copy code
val result = mutableMapOf<String, Int>().apply {
            w1.split(" ").forEach { put(it, getOrElse(it) { 0 } + 1) }
        }