Here you can find the source of median(List
Parameter | Description |
---|---|
list | a parameter |
public static Double median(List<Double> list)
//package com.java2s; /*L//from w w w . ja v a 2 s . c o m * Copyright SAIC * * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/stats-analysis/LICENSE.txt for details. */ import java.util.Collections; import java.util.List; public class Main { /** * This method returns you the median value for a List of Doubles * @param list * @return */ public static Double median(List<Double> list) { // List must be first sorted Collections.sort(list); int middle = list.size() / 2; // subscript of middle element if (list.size() % 2 == 1) { // Odd number of elements -- return the middle one. return list.get(middle); } else { // Even number -- return average of middle two // Must cast the numbers to double before dividing. return (list.get(middle - 1) + list.get(middle)) / 2.0; } } }