Java List Average average(List collection)

Here you can find the source of average(List collection)

Description

average

License

Open Source License

Declaration

public static double average(List<Long> collection) 

Method Source Code


//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
}

Related

  1. average(List collected)
  2. average(List arr)
  3. average(List list)
  4. average(List numbers)
  5. average(List observations)
  6. averageDouble(final List values)
  7. averageLog(List logList)
  8. averageValue(List oper)
  9. calculateAverage(final List durations)