Returns the sum of the items of the given collection. - Java java.util

Java examples for java.util:Collection Compare

Description

Returns the sum of the items of the given collection.

Demo Code


//package com.book2s;

import java.util.Collection;

public class Main {
    public static void main(String[] argv) {
        Collection c = java.util.Arrays.asList("asdf", "book2s.com");
        System.out.println(sum(c));
    }/*from ww w. j  a va 2s  . co m*/

    /**
     * Returns the sum of the items of the given collection.
     */
    public static float sum(Collection<Float> c) {
        float ret = 0;
        for (float i : c)
            ret += i;
        return ret;
    }
}

Related Tutorials