Sum up ArrayList via Java Stream [duplicate]

The mapToDouble call is not useless: it performs an implicit unboxing. Actually it’s the same as double totalevent = myList.stream().mapToDouble(f -> f.doubleValue()).sum(); Or double totalevent = myList.stream().mapToDouble(Double::doubleValue).sum(); Alternatively you can use summingDouble collector, but it’s not a big difference: double totalevent = myList.stream().collect(summingDouble(f -> f)); In my StreamEx library you can construct a DoubleStream directly … Read more

Decimal vs Double Speed

Floating point arithmetic will almost always be significantly faster because it is supported directly by the hardware. So far almost no widely used hardware supports decimal arithmetic (although this is changing, see comments). Financial applications should always use decimal numbers, the number of horror stories stemming from using floating point in financial applications is endless, … Read more