How to multiply values in a list using java 8 streams

后端 未结 4 635
长情又很酷
长情又很酷 2020-12-29 18:06

Is there a sum() equivalent method in stream which can perform multiplication of values given in a stream?

I\'ve a list of Integers like this :

List         


        
4条回答
  •  伪装坚强ぢ
    2020-12-29 18:59

    And here is an example for decimal products:

    // Some list
    List values;
    ...
    double product = values.stream()
        .reduce(1.0, (acc, value) -> acc * value)
        .doubleValue();
    

提交回复
热议问题