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

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -