codecamp

Clojure Maps contains

查看映射是否包含必需的键。

语法

以下是语法。

(contains hmap key)

参数 - 'hmap'是哈希键和值的映射。‘key’是需要在映射中搜索的键。

返回值 - 如果键存在,则返回true,否则返回false。

例子

以下是Clojure中contains的例子

(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)

输出

上述代码输出以下结果。

true
false


温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定