Java List Median median(ArrayList values)

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

Description

median

License

Apache License

Declaration

public static double median(ArrayList<Double> values) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

public class Main {
    public static double median(ArrayList<Double> values) {
        double[] arr = new double[values.size()];
        for (int ii = 0; ii < arr.length; ii++) {
            arr[ii] = values.get(ii);//from   w  w  w. ja v a2  s.c  om
        }
        return median(arr);
    }

    public static double median(double[] values) {
        double[] copy = new double[values.length];
        System.arraycopy(values, 0, copy, 0, values.length);
        java.util.Arrays.sort(copy);
        int length = values.length;
        if (length % 2 != 0) {
            return copy[length / 2];
        } else {
            return ((double) (copy[length / 2 - 1] + copy[length / 2])) / 2;
        }
    }
}

Related

  1. getMedian(Collection list)
  2. getMedian(List list)
  3. getMedian(List numbers)
  4. getMedian(List results)
  5. getMedianValue(List nums)
  6. median(final List array)
  7. median(List data)
  8. median(List list)
  9. median(List list)