Here you can find the source of median(List extends Number> data)
public static double median(List<? extends Number> data)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Gabriel Skantze.//from ww w. j a v a 2s . c om * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Gabriel Skantze - initial API and implementation ******************************************************************************/ import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static double median(List<? extends Number> data) { ArrayList<Double> sorted = new ArrayList<Double>(data.size()); for (int i = 0; i < data.size(); i++) { sorted.add(data.get(i).doubleValue()); } Collections.sort(sorted); if (sorted.size() % 2 == 1) { return sorted.get(sorted.size() / 2); } else { int mid = sorted.size() / 2 - 1; return (sorted.get(mid) + sorted.get(mid + 1)) / 2; } } }