Here you can find the source of sumUp(final List
Parameter | Description |
---|---|
list | the list of which the elements shall be summed up |
public static double sumUp(final List<Double> list)
//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; } }