Java Number Sum sum(final Iterable values)

Here you can find the source of sum(final Iterable values)

Description

Calculates the sum of a Collection

License

Open Source License

Declaration

public static double sum(final Iterable<Double> values) 

Method Source Code

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

public class Main {
    /**//from   ww w  .j av  a  2  s.c  om
     * Calculates the sum of an Array
     */
    public static double sum(final double... array) {
        double sum = 0;
        for (final double element : array) {
            sum += element;
        }
        return sum;
    }

    /**
     * Calculates the sum of a Collection
     */
    public static double sum(final Iterable<Double> values) {
        double sum = 0;
        for (final Double element : values) {
            sum += element;
        }
        return sum;
    }
}

Related

  1. sum(double a, double b)
  2. sum(double start, double end, double step)
  3. sum(double x, double y)
  4. sum(double x, double y)
  5. sum(final Iterable ns)
  6. sum(int a, int b)
  7. sum(int matrix1, int matrix2)
  8. sum(Iterable as)