get value from map code example

Example 1: node get value from map

let myMap = new Map();

myMap.set("key1", "value1");
myMap.set("key2", "value2");

console.log(myMap.has("key1")); // true
console.log(myMap.has("key2")); // true

console.log(myMap.get("key1")); // value1
console.log(myMap.get("key2")); // value2

// NOTE: DO NOT try to access map values using [].
// myMap["key1"] = "value1";

Example 2: hashmap get value by key java

import java.util.HashMap;
//Within a class
//You can do new HashMap<Key Type, Value Type>();, but you don't need to
HashMap<Int, String> examplehashmap=new HashMap<>();
{
//put in values
 examplehashmap.put(5, "example");
};
//get value
examplehashmap.get(5);
//returns "example"