Returns the combined value of all entries in the Integer Collection - Java java.util

Java examples for java.util:Collection Search

Description

Returns the combined value of all entries in the Integer Collection

Demo Code


//package com.java2s;
import java.util.Collection;

public class Main {
    public static void main(String[] argv) {
        Collection list = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(valueTotal(list));
    }/* w  w  w.ja v a  2  s.  com*/

    /**
     * Returns the combined value of all entries in the
     * Integer Collection
     *
     * @param list List
     * @return Integer
     */
    public static int valueTotal(Collection<Integer> list) {
        int total = 0;

        for (Integer value : list) {
            total += value;
        }

        return total;
    }
}

Related Tutorials