Here you can find the source of median(int[] vals)
public static double median(int[] vals)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { public static double median(int[] vals) { int[] copy = Arrays.copyOf(vals, vals.length); Arrays.sort(copy);/*ww w .j a v a2 s . co m*/ if (copy.length % 2 == 0) { int acc = copy[copy.length / 2]; acc += copy[(copy.length / 2) - 1]; return acc / 2.0; } else { return copy[copy.length / 2]; } } public static double median(double[] vals) { double[] copy = Arrays.copyOf(vals, vals.length); Arrays.sort(copy); if (copy.length % 2 == 0) { double acc = copy[copy.length / 2]; acc += copy[(copy.length / 2) - 1]; return acc / 2.0; } else { return copy[copy.length / 2]; } } }