Map get value java code example
Example 1: java map get the key from value
public static <T, E> Set<T> getKeyByValue(Map<T, E> map, E value) {
return map.entrySet()
.stream()
.filter(entry -> Objects.equals(entry.getValue(), value))
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
}
Example 2: hashmap get value java
import java.util.HashMap;
HashMap<String, String> dir = new HashMap<String, String>();
dir.put("hi", "hello");
dir.put("wow", "amazing");
System.out.println(dir.get("hi");
Example 3: hashmap get value by key java
import java.util.HashMap;
HashMap<Int, String> examplehashmap=new HashMap<>();
{
examplehashmap.put(5, "example");
};
examplehashmap.get(5);
Example 4: get value of map java
Hash_Map.get(Object key_element)