Java Utililty Methods Array Sum

List of utility methods to do Array Sum

Description

The list of methods to do Array Sum are organized into topic(s).

Method

longsum(long[] array)
sum
if (array == null) {
    return 0L;
long sum = 0;
for (int i = 0; i < array.length; i++) {
    sum += array[i];
return sum;
...
longsum(long[] counts)
sum
long sum = 0;
for (int i = 0; i < counts.length; i++) {
    sum += counts[i];
return sum;
doublesum(Number... numbers)
to overcome Exception occur when Integer, Double or other Number object is null when try to do mathematics operation (+-/*).
double total = 0;
for (Number number : numbers) {
    total += toDouble(number);
return total;
doublesum(Number[] array)
Returns sum of all the elements in the array.
double result;
int i;
result = 0.0;
for (i = 0; i < array.length; i++)
    result += array[i].doubleValue();
return result;
Numbersum(Number[] numbers)
Sums an array of numbers together while using the correct class type.
Number newSum = (Number) getObject(numbers);
if (newSum == null) {
    return null;
if (newSum instanceof Integer) {
    int sum = 0;
    int nextValue;
    for (int i = 0; i < numbers.length; i++) {
...
Object[]sum(Object[] srcOne, Object[] srcTwo)
sum
Object[] result = new Object[srcOne.length + srcTwo.length];
System.arraycopy(srcOne, 0, result, 0, srcOne.length);
System.arraycopy(srcTwo, 0, result, srcOne.length, srcTwo.length);
return result;
intsum(short tab[], int a, int b)
sum
int sum = 0;
for (int i = a; i <= b; i++) {
    sum += tab[i];
return sum;
intsum(short[] ary)
Sum of an array
return sum(ary, 0, ary.length);
Stringsum(String[] tokens, int start, int length, String separator)
sum
StringBuffer buffer = new StringBuffer();
for (int i = start; i < length + start; i++) {
    buffer.append(tokens[i]);
    if (i != length + start - 1) {
        buffer.append(separator);
return buffer.toString();
...
double[]sum3(double[] a, double[] b)
get the sum of two 3-dimension vector
return new double[] { a[0] + b[0], a[1] + b[1], a[2] + b[2] };