Here you can find the source of average(List
public static double average(List<Long> collection)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { public static double average(List<Long> collection) { if (collection == null || collection.size() == 0) return 9; if (collection.size() == 1) return collection.get(0); double average = collection.get(0); for (int i = 1; i < collection.size(); i++) average = i * (average + collection.get(i).doubleValue() / i) / (i + 1); return average; }//from w w w . ja v a 2 s . c om }