Java mean Mean(ArrayList values)

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

Description

Calculates the mean (average) value from a list of numeric values.

License

Open Source License

Parameter

Parameter Description
values List of numeric values

Exception

Parameter Description
Exception an exception

Return

Mean (average) value

Declaration

public static double Mean(ArrayList<Double> values) throws Exception 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.util.*;

public class Main {
    /** Calculates the mean (average) value from a list of numeric values.
     *//  w w w  .  j  ava 2 s. c  o m
     * @param values List of numeric values
     * @return Mean (average) value
     * @throws Exception
     */
    public static double Mean(ArrayList<Double> values) throws Exception {
        if (values.size() == 0)
            throw new Exception("Cannot determine mean on an empty list.");

        return Sum(values) / (double) values.size();
    }

    /** Calculates the sum of a list of numeric values.
     *
     * @param values List of numeric values
     * @return Summed value
     */
    public static double Sum(ArrayList<Double> values) {
        double sum = 0.0;

        for (double value : values)
            sum += value;

        return sum;
    }
}

Related

  1. calculateMeanOfArrayListDouble(List dList)
  2. getMean(ArrayList> lists)
  3. getMean(ArrayList beats)
  4. getMean(final Integer[] values)
  5. getMeanValue(ArrayList values)
  6. mean(Collection terms)
  7. mean(double a, double b)
  8. mean(double ask, double bid)
  9. mean(Double totalValue, int numValues)