Here you can find the source of sum(final int[] values)
Parameter | Description |
---|---|
values | the array to be summed, cannot be <code>null</code> |
public static int sum(final int[] values)
//package com.java2s; //License from project: Open Source License public class Main { /**// www . j a v a 2s .c om * Computes the sum of an array of integers. * <p> * Does not check for overflow of the result. * * @param values the array to be summed, cannot be <code>null</code> * @return the sum of all values in the array */ public static int sum(final int[] values) { int t = 0; for (int i : values) { t += i; } return t; } /** * Computes the sum of an array of longs. * <p> * Does not check for overflow of the result. * * @param values the array to be summed, cannot be <code>null</code> * @return the sum of all values in the array. */ public static long sum(final long[] values) { int t = 0; for (long i : values) { t += i; } return t; } }