/** * */ package com.baeldung.map; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.stream.Stream; /** * @author swpraman * */ public class MapUtil { public static Stream keys(Map map, V value) { return map.entrySet() .stream() .filter(entry -> value.equals(entry.getValue())) .map(Map.Entry::getKey); } public static Set getKeys(Map map, V value) { Set keys = new HashSet<>(); for (Entry entry : map.entrySet()) { if (entry.getValue().equals(value)) { keys.add(entry.getKey()); } } return keys; } public static K getKey(Map map, V value) { for (Entry entry : map.entrySet()) { if (entry.getValue().equals(value)) { return entry.getKey(); } } return null; } }