Java Utililty Methods Collection Average

List of utility methods to do Collection Average

Description

The list of methods to do Collection Average are organized into topic(s).

Method

doubleaverage(Collection a)
Compute the average for a Collection of numeric types
double sum = 0;
for (Object x : a) {
    if (x instanceof Double) {
        sum += (Double) x;
    } else if (x instanceof Long) {
        sum += (Long) x;
    } else if (x instanceof Integer) {
        sum += (Integer) x;
...
doubleaverage(Collection col)
average
return sum(col) / col.size();
doubleaverage(Collection sizes)
average
double sum = 0.0;
int count = sizes.size();
for (double size : sizes) {
    sum += size;
return count > 0 ? sum / count : 0.0;
Doubleaverage(Collection values)
average
List<Double> filteredValues = filterNulls(values);
if (filteredValues.size() == 0)
    return null;
double sum = 0;
for (Double value : filteredValues) {
    sum += value;
return sum / filteredValues.size();
...
longaverage(Collection values)
average
long avg = 0;
for (Long value : values) {
    avg += value;
return avg / values.size();
doubleaverage(Collection values)
average
double average = 0;
for (T value : values)
    average += value.doubleValue();
average /= values.size();
return average;
doubleaverage(Collection values)
average
double sum = 0;
for (Number value : values) {
    sum += value.doubleValue();
return sum / values.size();