remove all entries from hashmap java code example
Example: how to delete all elements from hashmap in java except one
map.keySet().removeIf(k -> !(k.equals(Constants.search) || k.equals(Constants.context)));
map.keySet().removeIf(k -> !(k.equals(Constants.search) || k.equals(Constants.context)));