Suppose I have this class:
public class Borrow {
private Float perCent;
private Float rate;
}
and I have a list of objects Borrow:
List<Borrow> moneyBorrowed = new ArrayList<Borrow>();
For each element, BorrowI need to multiply perCentby rateand summarize all the results.
I want to use a lambda expression in Java 8. I want to use something like this:
moneyBorrowed.stream().forEach(p -> {
p.getPerCent() * p.getRate()
}).sum();
but Iโm not very lucky ...
Any suggestion?
source
share