How to multiply values in a list using java 8 streams

后端 未结 4 678
长情又很酷
长情又很酷 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 19:10

    Try reduce of streams, it should help.

    Like:

    listOfIntegers.stream().reduce(1, (a, b) -> a * b)
    

    This link provides more information on how to use reduce.

提交回复
热议问题