Clojure – Maps contains?

Clojure maps contains?

In this guide, we will discuss Clojure Maps contains? See whether the map contains a required key.

Syntax

Following is the syntax.

(contains hmap key)

Parameters − ‘hmap’ is the map of hash keys and values. ‘key’ is the key which needs to be searched in the map.

Return Value − Returns the value of true if the key is present, else returns false.

Example

Following is an example of contains? in Clojure.

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (def demokeys (hash-map "z" "1" "b" "2" "a" "3"))
   (println (contains? demokeys "b"))
   (println (contains? demokeys "x")))
(example)

Output

The above code produces the following output.

true
false

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply