Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

clojure
map
community creator

What is the get method of a map in Clojure?

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

A map is a collection that assigns keys to values. The get method is used to get the element of a collection by its key.

Syntax

(get hmap key)
map get method

Parameters

The get method receives two parameters:

  1. hmap: The hash key and value
  2. key: The keys used to get the value

Return value

This method returns the value of the key passed.

Example

(ns clojure.examples.example
(:gen-class))
(defn gett []
(def keyss (hash-map "z" "1" "b" "22" "f" "53"))
(println keyss)
(println (get keyss "z")))
(gett)
map get method example

Explanation

  • Line 3: We define a gett function.
  • Line 4: We define a variable, keyss, using the def keyword. Next, we give it the collection.(hashmap "z" "1" "b" "22" "f" "53").
  • Line 5: We print the collection that contains both the keys and the value using the println. The get method is used to get the data value using key.
  • Line 6: We use the println to print the value returned by the key z.
  • Line 7: We call the gett function.

RELATED TAGS

clojure
map
community creator

CONTRIBUTOR

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring