Here you can find the source of mean(Collection
public staticdouble mean(Collection<Number> vector)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /**//from w w w . j a va 2 s. c o m * Computes the mean for an array of Numbers. * * @param vector * the array * @return the mean */ public static/* @pure@ */double mean(Number[] vector) { double sum = 0; if (vector.length == 0) { return 0; } for (int i = 0; i < vector.length; i++) { sum += vector[i].doubleValue(); } return sum / (double) vector.length; } public static/* @pure@ */double mean(Collection<Number> vector) { return mean(vector.toArray(new Number[vector.size()])); } public static/* @pure@ */double mean(double[] vector) { double sum = 0; if (vector.length == 0) { return 0; } for (int i = 0; i < vector.length; i++) { sum += vector[i]; } return sum / (double) vector.length; } }