Here you can find the source of Median(ArrayList
Parameter | Description |
---|---|
values | List of numeric values |
public static double Median(ArrayList<Double> values)
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.util.*; public class Main { /** Calculates the median value from a list of numeric values. */*w w w . j av a 2 s . c o m*/ * @param values List of numeric values * @return Median value */ public static double Median(ArrayList<Double> values) { Collections.sort(values); if (values.size() % 2 == 1) return values.get((values.size() + 1) / 2 - 1); else { double lower = values.get(values.size() / 2 - 1); double upper = values.get(values.size() / 2); return (lower + upper) / 2.0; } } }