Java Array Sum sum(Integer... integers)

Here you can find the source of sum(Integer... integers)

Description

build the sum of given Integers regardless of null {Category} NumberUtil {talendTypes} int | Integer {param} int(2,5,99,120) integers: integers to sum.

License

Apache License

Declaration

public static int sum(Integer... integers) 

Method Source Code

//package com.java2s;
/**/*from  w w w  .  j  a  va  2 s .  c o  m*/
 * Copyright 2015 Jan Lolling jan.lolling@gmail.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * build the sum of given Integers regardless of null
     * 
     * {Category} NumberUtil
     * 
     * {talendTypes} int | Integer
     * 
     * {param} int(2,5,99,120) integers: integers to sum.
     * 
     * {example} sum(25,2,4,25,66) result: 8889
     * 
     */
    public static int sum(Integer... integers) {
        int sum = 0;
        for (Integer i : integers) {
            if (i != null) {
                sum = sum + i.intValue();
            }
        }
        return sum;
    }
}

Related

  1. sum(int[] source)
  2. sum(int[] values)
  3. sum(int[] values)
  4. sum(int[] values, int begin, int end)
  5. sum(int[] values, int startIndex, int stopIndex)
  6. sum(Integer... ints)
  7. sum(Integer[] array)
  8. sum(long array[])
  9. sum(long... values)