Java Array Sum sum(final int base, final int[] ints)

Here you can find the source of sum(final int base, final int[] ints)

Description

sum

License

Open Source License

Declaration

public static int sum(final int base, final int[] ints) 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.util.ArrayList;
import java.util.Collection;

public class Main {
    public static int sum(int a, int b) {
        return sum(new int[] { a, b });
    }/*from   www.  j  a va 2 s. co m*/

    public static int sum(final Collection<Integer> ints) {
        return sum(0, ints);
    }

    public static int sum(final int[] ints) {
        return sum(0, ints);
    }

    public static int sum(final int base, final Collection<Integer> ints) {
        int ret = base;
        for (Integer i : ints)
            ret += i;
        return ret;
    }

    public static int sum(final int base, final int[] ints) {
        return sum(base, toIntegerCollection(ints));
    }

    public static Collection<Integer> toIntegerCollection(int[] ints) {
        ArrayList<Integer> ret = new ArrayList<Integer>();
        for (int i : ints)
            ret.add(new Integer(i));
        return ret;
    }
}

Related

  1. sum(final Double[] doubles)
  2. sum(final double[] productMix)
  3. sum(final double[] target)
  4. sum(final double[] vec)
  5. sum(final float[] x)
  6. sum(final int[] terms, final int start, final int len)
  7. sum(final int[] values)
  8. sum(final int[] values, final int... indice)
  9. sum(final long... values)