Java List Sum sumListItems(List list)

Here you can find the source of sumListItems(List list)

Description

sum List Items

License

Open Source License

Declaration

public static String sumListItems(List list) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    public static String sumListItems(List list) {
        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);
        }//from   w ww .j  a v  a 2 s . co  m
        return String.valueOf(sum);
    }

    public static String valueOf(char c) {
        char ac[] = new char[1];
        ac[0] = c;
        return new String(ac);
    }

    public static String valueOf(double d) {
        return Double.toString(d);
    }

    public static String valueOf(float f) {
        return Float.toString(f);
    }

    public static String valueOf(int i) {
        char ac[] = new char[11];
        int j = ac.length;
        boolean flag = i < 0;
        if (!flag)
            i = -i;
        for (; i <= -10; i /= 10)
            ac[--j] = Character.forDigit(-(i % 10), 10);

        ac[--j] = Character.forDigit(-i, 10);
        if (flag)
            ac[--j] = '-';
        return new String(ac, j, ac.length - j);
    }

    public static String valueOf(long l) {
        return Long.toString(l, 10);
    }

    public static String valueOf(Object obj) {
        return obj != null ? obj.toString() : "";
    }

    public static String valueOf(boolean flag) {
        return flag ? "true" : "false";
    }

    public static String valueOf(char ac[]) {
        return new String(ac);
    }
}

Related

  1. sumCreditList(List list)
  2. sumDifferences(List a, List b)
  3. sumDouble(List list)
  4. sumInteger(List list)
  5. sumIntegers(List values)
  6. sumLog(List Q)
  7. sumLong(List list)
  8. sumOfSquares(List samples)
  9. sumOfSquares(List list)