Java Collection Mean mean(Collection data)

Here you can find the source of mean(Collection data)

Description

mean

License

Open Source License

Parameter

Parameter Description
data a parameter

Return

the mean

Declaration

public static Double mean(Collection<Double> data) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009, 2013, 2014 Matthew Purver, Queen Mary University of London.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html/*from www .  ja va 2 s . c o m*/
 ******************************************************************************/

import java.util.Collection;

public class Main {
    /**
     * @param data
     * @return the mean
     */
    public static Double mean(Collection<Double> data) {
        return (sum(data) / (double) data.size());
    }

    /**
     * @param data
     * @return the mean
     */
    public static double mean(double[] data) {
        return (sum(data) / (double) data.length);
    }

    /**
     * @param data
     * @return the sum
     */
    public static Double sum(Collection<Double> data) {
        Double sum = 0.0;
        for (Double datum : data) {
            sum += datum;
        }
        return sum;
    }

    /**
     * @param data
     * @return the sum
     */
    public static double sum(double[] data) {
        double sum = 0.0;
        for (double datum : data) {
            sum += datum;
        }
        return sum;
    }
}

Related

  1. getMean(Collection cluster)
  2. getMean(final Collection collection)
  3. getVariance(Collection data, Number mean)
  4. mean(Collection coll)
  5. mean(Collection nums)
  6. mean(Collection dist)
  7. mean(Collection vector)
  8. mean(final Collection values)
  9. mean(final Collection values)