How to remove multiple elements from Set/Map AND knowing which ones were removed?
问题 I have a method that has to remove any element listed in a (small) Set<K> keysToRemove from some (potentially large) Map<K,V> from . But removeAll() doesn't do, as I need to return all keys that were actually removed, since the map might or might not contain keys that require removal. Old-school code is straight forward: public Set<K> removeEntries(Map<K, V> from) { Set<K> fromKeys = from.keySet(); Set<K> removedKeys = new HashSet<>(); for (K keyToRemove : keysToRemove) { if (fromKeys