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
Post a Comment