Functional Programming - Sum

About

Snippet

Java

Java - Stream Processing

  • From a collection of object that return an exit status
Integer errors = insertStreamListeners
                .stream()
                .mapToInt(s -> s.getExitStatus()>0?1:0)
                .sum();
  • Where myMao is map where the values are integers
Integer tot = myMap
    .values()
    .stream()
    .mapToInt(s->s)
    .sum()

Powered by ComboStrap