Java List Average getAverage(List values)

Here you can find the source of getAverage(List values)

Description

Returns the average of the given values.

License

Open Source License

Parameter

Parameter Description
values the values.

Return

the average.

Declaration

public static Double getAverage(List<Double> values) 

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    /**//from   ww w  .j ava 2 s.c om
     * Returns the average of the given values.
     * 
     * @param values the values.
     * @return the average.
     */
    public static Double getAverage(List<Double> values) {
        Double sum = getSum(values);

        return sum / values.size();
    }

    /**
     * Returns the sum of the given values.
     * 
     * @param values the values.
     * @return the sum.
     */
    public static Double getSum(List<Double> values) {
        Double sum = 0.0;

        for (Double value : values) {
            if (value != null) {
                sum += value;
            }
        }

        return sum;
    }
}

Related

  1. computeAverage(List aList)
  2. getAverage(int period, List timeline)
  3. getAverage(List list)
  4. getAverage(List l)
  5. getAverage(List values)
  6. getAverage(List values)
  7. getAverage(List numbers)
  8. getAverageColour(List colours)
  9. getAverageDuration(List durations)