Java Utililty Methods List Sum

List of utility methods to do List Sum

Description

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

Method

ListsumAllColumnsOfMatrix(List> matrix)
sum All Columns Of Matrix
List<Integer> result = new ArrayList<Integer>();
for (int i = 0; i < matrix.size(); i++) {
    Integer columnTotal = 0;
    for (int j = 0; j < matrix.size(); j++) 
        List<Integer> row = matrix.get(j);
        for (int k = 0; k < row.size(); k++) 
            if (k == i) {
                columnTotal = (columnTotal + row.get(k)) % 26;
                break;
    result.add(columnTotal);
return result;
StringsumCreditList(List list)
Creates the sum of a list of credit ranges, returning the cumulative min and max credits eg "1-2", "3-5" would return "4-7"
if (list == null || list.isEmpty())
    return "0";
float minCredits = 0;
float maxCredits = 0;
for (String item : list) {
    String[] split = item.split("[ ,/-]");
    String first = split[0];
    float min = Float.parseFloat(first);
...
floatsumDifferences(List a, List b)
sum Differences
assert (a.size() == b.size());
float sumDiff = 0f;
for (int i = 0; i < a.size(); i++) {
    sumDiff += Math.abs(a.get(i) - b.get(i));
return (float) sumDiff;
doublesumDouble(List list)
sum Double
double sum = 0;
for (Double i : list) {
    if (i != null)
        sum += i;
return sum;
intsumInteger(List list)
sum Integer
int accumulator = 0;
if (list instanceof RandomAccess) {
    for (int i = 0; i < list.size(); i++) {
        accumulator += list.get(i);
} else {
    Iterator<Integer> iter = list.iterator();
    while (iter.hasNext())
...
intsumIntegers(List values)
sum Integers
int s = 0;
for (int v : values)
    s += v;
return s;
StringsumListItems(List list)
sum List Items
double sum = 0d;
for (int i = 0; i < list.size(); i++) {
    String value = (String) list.get(i);
    if (value == null || "".equals(value))
        continue;
    sum = sum + Double.parseDouble(value);
return String.valueOf(sum);
...
floatsumLog(List Q)
sum Log
float res = 0;
for (float f : Q) {
    res += Math.log(f);
return res;
longsumLong(List list)
Sum long.
long sum = 0;
for (int i = 0; i < list.size(); i++) {
    sum += list.get(i);
return sum;
doublesumOfSquares(List samples)
sum Of Squares
double sumOfSquares = 0;
for (double sample : samples) {
    sumOfSquares += sample * sample;
return sumOfSquares;