Validate your inputs
The median
and average
methods will throw an exception if the input array is empty. Think of the preconditions and if there are safe assumptions (input will never be empty) then document it, possibly with an assert statement.
Watch out for corner cases
This statement may overflow if the two numbers are too big:
return (numbers[middle - 1] + numbers[middle]) / 2.0;
Simplify
If you omit the second and third parameters of Arrays.sort
, by default it will use 0 and the length of the array. So you can omit these parameters in all your examples.
There is already a library method to calculate average:
return LongStream.of(numbers).average();