How do you sum on a list of objects in a java 8 stream -


in c# had this

list<learner> learners; double learnersum = this.learners.sum(learner => learner.predicted * learner.alpha); 

i want same in java 8. far

double learnersum = this.learners.stream()... 

it seems need reduce examples on simple arrays of integers. missing?

you can create doublestream stream, , use method sum sum.

double learnersum = learners.stream()     .maptodouble(l -> l.predicted * l.alpha).sum(); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -