Here you can find the source of mean(Collection extends Number> nums)
Parameter | Description |
---|---|
nums | Any descendant of Number (Integer, Short, Double, Float, etc) |
public static double mean(Collection<? extends Number> nums)
//package com.java2s; //License from project: Apache License import java.util.Collection; public class Main { /**/*from www . j ava 2s . co m*/ * @param nums Any descendant of Number (Integer, Short, Double, Float, etc) * @return The mean of the number, or Double.NaN if the list is empty. */ public static double mean(Collection<? extends Number> nums) { if (nums == null || nums.isEmpty()) { return Double.NaN; } double sum = 0.0; for (Number n : nums) { sum += n.doubleValue(); } return sum / nums.size(); } }