I have a simple class:
class Simple {
private String count;
private BigDecimal amount;
private String label;
}
and have a List: List<Simple> simples = new ArrayList<>();
how I can sum all amounts of all simples in list with Lambda in Java 8?
It is quite easy with a Stream and a reducer :
BigDecimal sum = simples
.stream()
.map(Simple::getAmount)
.reduce(BigDecimal::add)
.get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With