Kotlin: Returning True if Map Keys Match Up with Any of the Elements in a Set


val myMap: Map<String, String> = mapOf("mainVar" to 321, "key2" to 123)
val allowedMatches: Set<String> = setOf("key1", "key2", "key3", "key4")

//true, since myMap contains "key2":
var q = myMap.any{ allowedMatches.contains(it.key) } 

println("myMap contains an element from allowedMatches: ${q})

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s