Java List Mean computeMean(List fs)

Here you can find the source of computeMean(List fs)

Description

compute Mean

License

Open Source License

Declaration

public static double computeMean(List<? extends Number> fs) 

Method Source Code

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

import java.util.List;

public class Main {
    public static double computeMean(List<? extends Number> fs) {
        Double sum = 0.0;/* ww  w.j a  v a  2  s .c  om*/
        for (Number d : fs)
            sum += d.doubleValue();
        return sum / fs.size();
    }

    /**
     * This method computes the average of a list of doubles.
     * @param ds the list of numbers
     * @return the average of ds
     */
    public static double computeMean(double[] ds) {
        double d = 0;
        for (double n : ds)
            d += n;
        return d / ds.length;

    }

    /**
     * This method computes the average of a list of ints.
     * @param ds the list of numbers
     * @return the average of ds
     */
    public static double computeMean(int[] ds) {
        double d = 0;
        for (int n : ds)
            d += n;
        return d / ds.length;
    }
}

Related

  1. calculateStDev(List values, double mean)
  2. geometricMean(List vals, double replacement)
  3. getHMean(List harray)
  4. getMean(List data)
  5. getMean(List list)