How to multiply values in a list using java 8 streams -


is there sum() equivalent method in stream can perform multiplication of values given in stream?

i've list of integers :

list<integer> listofintegers = new arraylist<>(); listofintegers.addall(arrays.aslist(1,4,2,7,5)); 

i'm able sum of integers, unable find api can multiply values , give output.

listofintegers.stream().maptoint(a -> a).sum(); 

if try use foreach it, cannot store result final variables allowed used inside it.

is there alternative this?

try reduce of streams, should help.

like:

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

this link provides more information on how use reduce.


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -