Java List Sum sumUp(final List list)

Here you can find the source of sumUp(final List list)

Description

Sums up the elements in the list.

License

Apache License

Parameter

Parameter Description
list the list of which the elements shall be summed up

Return

the sum over all elements in the list

Declaration

public static double sumUp(final List<Double> list) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Iterator;
import java.util.List;

public class Main {
    /**// w ww  .  j  ava 2s .c  o  m
     * Sums up the elements in the list.
     *
     * <code>null</code> will be counted as 0.
     *
     * @param list
     *            the list of which the elements shall be summed up
     * @return the sum over all elements in the list
     */
    public static double sumUp(final List<Double> list) {
        assert null != list;

        double result = 0;
        final Iterator<Double> iter = list.iterator();
        while (iter.hasNext()) {
            final Double next = iter.next();
            if (null != next) {
                result += next.doubleValue();
            }
        }
        return result;
    }
}

Related

  1. sumLog(List Q)
  2. sumLong(List list)
  3. sumOfSquares(List samples)
  4. sumOfSquares(List list)
  5. sumTerms(List terms)
  6. sumWithDivide(List okaylist, int curdiv)