static void dropValuesFromMapOtherThan(Map map, B... values) { HashSet valueSet = new HashSet(Arrays.asList(values)); for (Iterator> it = map.entrySet().iterator(); it.hasNext();) if (!valueSet.contains(it.next().getValue())) it.remove(); }