Thanks everyone for all the suggestions and answers. This is very helpful and I learned a lot!
I decided to give most of your solutions a go (except for the JDK12 solution). For some of them you already provide me with the code. In addition, I made my own Collector
.
class extremesCollector implements Collector, Map> {
@Override
public Supplier
Results
I gave all of them a try and compared the results. Good news: for all of them, I got the same result as far as the values are concerned!
With respect to the speed, here is the ranking:
- for-loops
- four individual streams
- stream with self-made Collector
- parallel stream with self-made Collector
- statistics approach provided by Andrew Tobilko
Number 2 and 3 are actually very close in terms of speed. The parallel version is probably slower because my dataset is too small.