Please tell me there is a map
Map<Integer, Integer> denominations=new HashMap<>(); How can I use Stream API to remove all pairs whose value is zero?
Please tell me there is a map
Map<Integer, Integer> denominations=new HashMap<>(); How can I use Stream API to remove all pairs whose value is zero?
denominations = denominations.entrySet() .stream() .filter(e -> e.getValue() != 0) .collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue)); but it can be much easier without streams
denominations.entrySet() .removeIf(e -> e.getValue() == 0); .values().removeIf( ((Integer)0)::equals ); . In short, more mysterious and will not fall, if the map is null . - zRrrSource: https://ru.stackoverflow.com/questions/894418/
All Articles