Here you can find the source of calculateMean(Collection
public static double calculateMean(Collection<Double> values)
//package com.java2s; //License from project: Apache License import java.util.Collection; public class Main { public static double calculateMean(Collection<Double> values) { if (values == null || values.isEmpty()) { throw new IllegalArgumentException("Can not calculate mean of null or empty collection!"); }/*ww w . j ava 2s . co m*/ return (calcSum(values) / values.size()); } public static double calculateMean(double[] values) { if (values == null) { throw new IllegalArgumentException("Can not calculate mean of null!"); } return (calcSum(values) / values.length); } public static double calcSum(Collection<Double> values) { if (values == null) { throw new IllegalArgumentException("Can not calculate sum of null!"); } double sum = 0D; for (double d : values) { sum += d; } return sum; } public static double calcSum(double[] values) { if (values == null) { throw new IllegalArgumentException("Can not calculate sum of null!"); } double sum = 0D; for (double d : values) { sum += d; } return sum; } }