How to remove an element of a HashMap whilst streaming (lambda)

后端 未结 4 757
渐次进展
渐次进展 2020-12-13 23:44

I have the following situation where I need to remove an element from a stream.

map.entrySet().stream().filter(t -> t.getValue().equals(\"0\")).
                 


        
4条回答
  •  借酒劲吻你
    2020-12-14 00:21

    map.entrySet().removeIf(entry -> entry.getValue().equals("0"));
    

    You can't do it with streams, but you can do it with the other new methods.

    EDIT: even better:

    map.values().removeAll(Collections.singleton("0"));
    

提交回复
热议问题