Java Collection Mean mean(final Collection values)

Here you can find the source of mean(final Collection values)

Description

Calculates the mean of a Collection

License

Open Source License

Declaration

public static double mean(final Collection<Double> values) 

Method Source Code

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

import java.util.Collection;

public class Main {
    /**//from w w  w  .jav  a  2 s .c o m
     * Calculates the mean of a Collection
     */
    public static double mean(final Collection<Double> values) {
        return sum(values) / values.size();
    }

    /**
     * Calculates the sum of an Array
     */
    public static double sum(final double... array) {
        double sum = 0;
        for (final double element : array) {
            sum += element;
        }
        return sum;
    }

    /**
     * Calculates the sum of a Collection
     */
    public static double sum(final Iterable<Double> values) {
        double sum = 0;
        for (final Double element : values) {
            sum += element;
        }
        return sum;
    }
}

Related

  1. mean(Collection coll)
  2. mean(Collection nums)
  3. mean(Collection data)
  4. mean(Collection dist)
  5. mean(Collection vector)
  6. mean(final Collection values)
  7. meanAndVariance(Collection vector)