Here you can find the source of median(List
public static double median(List<Double> p)
//package com.java2s; //License from project: Apache License import java.util.Arrays; import java.util.List; public class Main { public static double median(List<Double> p) { Double[] b = new Double[p.size()]; int i = 0; for (Double entry : p) { b[i] = entry;/*from w w w. j a va 2 s . c om*/ i++; } Arrays.sort(b); if (p.size() % 2 == 0) { return (b[(b.length / 2) - 1] + b[b.length / 2]) / 2.0; } else { return b[b.length / 2]; } } }