What's the quickest way to remove an element from a Map by value in Java?

后端 未结 12 558
臣服心动
臣服心动 2020-12-09 01:36

What\'s the quickest way to remove an element from a Map by value in Java?

Currently I\'m using:

    DomainObj valueToRemove = new DomainObj();
    S         


        
12条回答
  •  抹茶落季
    2020-12-09 01:59

    map.values().removeAll(Collections.singleton(null));
    

    reference to How to filter "Null" values from HashMap?, we can do following for java 8:

    map.values().removeIf(valueToRemove::equals);
    

提交回复
热议问题