Java Collection Mean mean(Collection nums)

Here you can find the source of mean(Collection nums)

Description

mean

License

Apache License

Parameter

Parameter Description
nums Any descendant of Number (Integer, Short, Double, Float, etc)

Return

The mean of the number, or Double.NaN if the list is empty.

Declaration

public static double mean(Collection<? extends Number> nums) 

Method Source Code

//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();
    }
}

Related

  1. getMean(Collection data)
  2. getMean(Collection cluster)
  3. getMean(final Collection collection)
  4. getVariance(Collection data, Number mean)
  5. mean(Collection coll)
  6. mean(Collection data)
  7. mean(Collection dist)
  8. mean(Collection vector)
  9. mean(final Collection values)