🚍3. total height of characters

    Integer totalHeight = characters
                .stream()
                .mapToInt(Person::getHeight)
                .sum();
                
    //using reduce
          Integer heightSum =  characters.stream()
                .reduce(0,(height,person)->height+person.getHeight(),Integer::sum);
        System.out.printf("total height %d",heightSum);            

Last updated

Was this helpful?