List as an object field - how to handle it via Stream (Java 8)? -


there waybill object has set<packing> field, packing object has price field. list<waybill>. need calculate total cost of packing entire list<waybill>. how competently make through stream? thank you.

class waybill {     set<packing> setofpacking; }  class packing {     int price; }  list<waybill> allwaybills = ... 

import java.util.stream.*  list<waybill> allwaybills = ... int totalcost = allwaybills     .stream()     .maptoint(w -> w.setofpacking         .stream()         .maptoint(p -> p.price)         .sum()     )     .sum(); 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -