Java List Median median(List p)

Here you can find the source of median(List p)

Description

median

License

Apache License

Declaration

public static double median(List<Double> p) 

Method Source Code


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

import java.util.Arrays;
import java.util.List;

public class Main {
    public static double median(List<Double> p) {
        Double[] b = new Double[p.size()];
        int i = 0;
        for (Double entry : p) {
            b[i] = entry;/*from  w  w w.  j a  va 2 s .  c  om*/
            i++;
        }
        Arrays.sort(b);
        if (p.size() % 2 == 0) {
            return (b[(b.length / 2) - 1] + b[b.length / 2]) / 2.0;
        } else {
            return b[b.length / 2];
        }
    }
}

Related

  1. median(ArrayList values)
  2. median(final List array)
  3. median(List data)
  4. median(List list)
  5. median(List list)
  6. median(List sortedDataAscendingOrder)
  7. median(List list)
  8. median(List data)
  9. median(List data)