Here you can find the source of sum(Collection
public static double[] sum(Collection<double[]> vec)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { public static double[] sum(Collection<double[]> vec) { Iterator<double[]> iter = vec.iterator(); if (vec.size() <= 0) return null; double[] res = new double[iter.next().length]; while (iter.hasNext()) { double[] tmp = iter.next(); for (int i = 0; i < res.length; i++) { res[i] += tmp[i];/*from w w w . j a va2s. com*/ } } return res; } }