Java Median getMedianValue(ArrayList values)

Here you can find the source of getMedianValue(ArrayList values)

Description

get Median Value

License

Open Source License

Declaration

public static double getMedianValue(ArrayList<Double> values) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.Collections;

public class Main {
    public static double getMedianValue(ArrayList<Double> values) {
        if (values.isEmpty()) {
            return -1.0;
        }//  w w w.  j a v  a  2s . c  om

        Collections.sort(values);
        if (values.size() % 2 == 1) {
            return values.get(values.size() / 2 + 1);
        }

        double lower = values.get(values.size() / 2 - 1);
        double upper = values.get(values.size() / 2);

        return (lower + upper) / 2.0;
    }
}

Related

  1. calculateMedianOfArrayListInteger(List integerList)
  2. getMedian(double array[])
  3. getMedian(double[] a)
  4. getmedian(double[] vals, int nvalindex)
  5. getMedian(int[] array)
  6. median(ArrayList v)
  7. median(ArrayList values)
  8. Median(ArrayList values)
  9. median(double... a)