public static void removeItemFromMap(HashMap<String, Integer> map) { HashMap<String, Integer> copy = new HashMap<>(map); for (HashMap.Entry<String, Integer> pair : copy.entrySet()){ if (pair.getValue()<500){ map.remove(pair.getKey());} } }