Here you can find the source of median(ArrayList
public static double median(ArrayList<Double> values)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; public class Main { public static double median(ArrayList<Double> values) { double[] arr = new double[values.size()]; for (int ii = 0; ii < arr.length; ii++) { arr[ii] = values.get(ii);//from w w w. ja v a2 s.c om } return median(arr); } public static double median(double[] values) { double[] copy = new double[values.length]; System.arraycopy(values, 0, copy, 0, values.length); java.util.Arrays.sort(copy); int length = values.length; if (length % 2 != 0) { return copy[length / 2]; } else { return ((double) (copy[length / 2 - 1] + copy[length / 2])) / 2; } } }