Java List Median medianDouble(List vals)

Here you can find the source of medianDouble(List vals)

Description

median Double

License

Open Source License

Declaration

public static double medianDouble(List<Double> vals) 

Method Source Code


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

import java.util.ArrayList;

import java.util.Collections;
import java.util.List;

public class Main {
    public static double medianDouble(List<Double> vals) {
        List<Double> copy = new ArrayList<Double>(vals);
        Collections.sort(copy);/* w  ww. j a v  a2s  . com*/

        if (copy.size() % 2 == 0) {
            Double acc = copy.get(copy.size() / 2);
            acc += copy.get((copy.size() / 2) - 1);
            return acc / 2.0;
        } else {
            return copy.get(copy.size() / 2);
        }
    }
}

Related

  1. median(List list)
  2. median(List data)
  3. median(List data)
  4. medianAbsVal(List vals)
  5. medianAbsValAboveThresh(List vals, double thresh)
  6. mediane(List liste)