How to filter stream expression to throw exception?
I have function to check sum of list elements, if sum is more than 1 -> throw exception
Double sum = list.stream().map(element::getNumber).reduce(0.0,Double::sum);
if(sum>1){
throw new Exception("message);
}
Is it possible to add if
condition to stream expression to get rid of the additional if
condition?