I want to iterate an array with some objects that contains a quantity and get the totalQuantity, but using the new API of Java 8 instead of the tipical for each loop.
This is the way I'm doing so far:
int totalQuantityOrdered=0;
totalQuantityOrdered=CollectionUtils.isNotEmpty(details)?details.stream().forEach(detail->totalQuantityOrdered+=detail.getOrderHeader().getQuantity()):totalQuantityOrdered;
However I'm getting a compilation error telling me that in order to use a lambda expression the variable totalQuantityOrdered has to be final. Then I think when a variable is final means that its value cannot be modified, so in that case how do I achieve what I'm trying to do?
Thnk you in advance for your time.