Java List Sum sumInteger(List list)

Here you can find the source of sumInteger(List list)

Description

sum Integer

License

LGPL

Declaration

public static final int sumInteger(List<Integer> list) 

Method Source Code

//package com.java2s;
/*/*  w w  w  . ja  va2 s  .  c  om*/
This code is licensed under the LGPL v3 or greater with the classpath exception, 
with the following additions and exceptions.  
    
packages cern.* have retained the original cern copyright notices.
    
packages at.mabs.cmdline and at.mabs.util.* 
have the option to be licensed under a BSD(simplified) or Apache 2.0 or greater  license 
in addition to LGPL. 
    
Note that you have permission to replace this license text to any of the permitted licenses. 
    
Main text for LGPL can be found here:
http://www.opensource.org/licenses/lgpl-license.php
    
For BSD:
http://www.opensource.org/licenses/bsd-license.php
    
for Apache:
http://www.opensource.org/licenses/apache2.0.php
    
classpath exception:
http://www.gnu.org/software/classpath/license.html
*/

import java.util.*;

public class Main {
    public static final int sumInteger(List<Integer> list) {
        int accumulator = 0;
        if (list instanceof RandomAccess) {
            for (int i = 0; i < list.size(); i++) {
                accumulator += list.get(i);
            }
        } else {
            Iterator<Integer> iter = list.iterator();
            while (iter.hasNext())
                accumulator += iter.next();
        }
        return accumulator;
    }
}

Related

  1. sumAll(List list)
  2. sumAllColumnsOfMatrix(List> matrix)
  3. sumCreditList(List list)
  4. sumDifferences(List a, List b)
  5. sumDouble(List list)
  6. sumIntegers(List values)
  7. sumListItems(List list)
  8. sumLog(List Q)
  9. sumLong(List list)