I am trying to apply a filter to a Map. The intention is to keep only those keys which are part of a set. The following implementation does provide the required results but I want to know if this is the right way?
private void filterProperties(Map<String, Serializable> properties, Set<String> filterSet) {
Set<String> keys = properties.keySet();
keys.retainAll(filterSet);
}
Yes!
(see: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/HashMap.html#keySet())