Kotlin, Software Development

Kotlin – Check if key exists in Map

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




Got comments, or suggestions? Please visit our Facebook page!

You Might Also Like


  1. 1
  2. 2
  3. 3

    Hey FYI, you can embed the Kotlin Playground directly into your page, and allow users to edit/run code snippets. I understand if you don’t want that for consistency elsewhere on your site, just a thought.

  4. 4

Comments are closed.