Java Collection Sum sum(Collection values)

Here you can find the source of sum(Collection values)

Description

sum

License

Open Source License

Declaration

public static Double sum(Collection<Double> values) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

public class Main {
    public static Double sum(Collection<Double> values) {
        List<Double> filteredValues = filterNulls(values);
        if (filteredValues.size() == 0)
            return null;

        double sum = 0;
        for (Double value : filteredValues) {
            sum += value;/*from   w  w w.  j  av  a  2 s . co m*/
        }
        return sum;
    }

    private static List<Double> filterNulls(Collection<Double> values) {
        List<Double> result = new ArrayList<>();
        for (Double value : values) {
            if (value != null)
                result.add(value);
        }

        return result;
    }
}

Related

  1. sum(Collection numbers)
  2. sum(Collection collection)
  3. sum(Collection list)
  4. sum(Collection values)
  5. sum(Collection values)
  6. sum(Collection values)
  7. sum(Collection vec)
  8. sum(Collection values)