Код: Выделить всё
public class Order {
private List orderLines;
private String name;
// ... lots of other fields
// Getters & setters & ctors down here
}
public class OrderLine {
private String productId;
private Integer quantity;
// Getters & setters & ctors down here
}
Код: Выделить всё
int totalQuantity = 0;
for (OrderLine ol : order.getOrderLines()) {
totalQuantity += ol.getQuantity();
}
Код: Выделить всё
Integer totalQuantity = order.getOrderLines().stream().filter(ol -> ol.getQuantity());
Любые идеи, где я пойдет не так?
Подробнее здесь: https://stackoverflow.com/questions/567 ... stream-api
Мобильная версия