Home » Android » android – How to get key for value from Hashmap in Kotlin?

android – How to get key for value from Hashmap in Kotlin?

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have HashMap in Kotlin

val map = HashMap<String, String>()

I want to know how to get key for a particular value from this HashMap without iterating through complete HashMap?

How to&Answers:

Using filterValues {}

val map = HashMap<String, String>()
val keys = map.filterValues { it == "your_value" }.keys

And keys will be the set of all keys matching the given value