List of usage examples for java.util Arrays sort
public static void sort(Object[] a)
From source file:es.ucm.fdi.ac.outlier.Hampel.java
/** * median of an array/*from w w w. ja v a 2 s.c o m*/ */ public static double median(double[] array) { Arrays.sort(array); // sort the elements boolean even = (array.length % 2) == 0; double median = 0; if (even) { int rightNumber = array.length / 2; int leftNumber = rightNumber - 1; // return average of two center-elements median = (array[rightNumber] + array[leftNumber]) / 2; } else { // choose the center one median = array[array.length / 2]; } return median; }