Move the empty list check before sorting to avoid processing an empty collection and provide clearer error handling.
Num4j
num4j provides some mathematical algorithms and utilities such as chained high-precision mathematical calculator and percentile statistic algorithm.