I can imagine many ways to do this but the simplest one I have is to simply sort the array in ascending order and then subtract the last element from the first.
I don't know if performance would be better to manually find the largest and smallest or not. Sometimes the methods Oracle provides are more efficient.
Code
Arrays.sort(numbers);//Arrays.parallelSort(numbers);
return numbers[4] - numbers[0];//return numbers[numbers.length - 1] - numbers[0];I don't know if performance would be better to manually find the largest and smallest or not. Sometimes the methods Oracle provides are more efficient.
