I have a List<BigInteger> listBigInt
. Some of the items are null
some are not.
I want all the items (except the null
values) multiplied by five and summed using java8 streams.
So far I fugured out this construct:
BigDecimal sum = listBigInt.stream()
.map(c -> (c == null ? BigDecimal.ZERO : c).multiply(new BigDecimal(5)))
.reduce(BigDecimal::add).get();
Is there more elegant way to avoid null values?