1public static <T, E> Set<T> getKeyByValue(Map<T, E> map, E value) {
2 return map.entrySet()
3 .stream()
4 .filter(entry -> Objects.equals(entry.getValue(), value))
5 .map(Map.Entry::getKey)
6 .collect(Collectors.toSet());
7}
1import java.util.HashMap;
2//Within a class
3//You can do new HashMap<Key Type, Value Type>();, but you don't need to
4HashMap<Int, String> examplehashmap=new HashMap<>();
5{
6//put in values
7 examplehashmap.put(5, "example");
8};
9//get value
10examplehashmap.get(5);
11//returns "example"