4

Kotlin – Check if key exists in Map

Last Updated on

This post shows sample codes that check if a key exists in a map. There are 3 ways to do this in Kotlin. We are using Kotlin 1.3.

Map.containsKey(key: String)

Map.contains(key: String)

This one is a bit special. The documentation says:

x in map

Output:

References

https://kotlinlang.org/docs/reference/collections.html

Avatar

Karl San Gabriel

Professional Software Developer