get Average of Long List - Java Collection Framework

Java examples for Collection Framework:List

Description

get Average of Long List

Demo Code


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

public class Main {


    public static float getAverage(List<Long> allTimes) {
        long total = getTotal(allTimes);
        return total / (float) allTimes.size();
    }//ww w  .j  a  v  a 2 s.c o m

    public static long getTotal(List<Long> times) {
        long total = 0;
        for (Long time : times) {
            total = total + time;
        }
        return total;
    }
}

Related Tutorials