Java Collection Sum sum(Collection values)

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

Description

Calculate sum

License

Open Source License

Parameter

Parameter Description
values a parameter

Declaration

public static double sum(Collection<Double> values) 

Method Source Code


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

import java.util.Collection;

public class Main {
    public static double sum(double[] values) {
        double sum = 0.0;
        for (int i = 0; i < values.length; i++) {
            sum += values[i];/*from  w w  w  .j  a  va  2  s .  c o  m*/
        }
        return sum;
    }

    /**
     * Calculate sum
     * @param values
     * @return
     */
    public static double sum(Collection<Double> values) {

        double sum = 0.0;

        for (Double value : values) {
            sum += value;
        }

        return sum;
    }
}

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)
  9. sum(Collection collection)