Java Utililty Methods Array Average

List of utility methods to do Array Average

Description

The list of methods to do Array Average are organized into topic(s).

Method

doubleaverage(double[] array)
average
return average(array, array.length);
doubleaverage(double[] d)
Mittelwertberechnung.
double average = average1(d);
if (Double.isNaN(average) || Double.isInfinite(average))
    return average2(d);
return average;
doubleaverage(double[] values)
Get the average of an array of values.
double sum = 0;
if (values.length == 0) {
    throw new IllegalArgumentException("Array length must be > 0");
for (int i = 0; i < values.length; i++) {
    sum += values[i];
return sum / values.length;
...
doubleaverage(double[] values)
average
double ret = 0;
for (int i = 0; i < values.length; i++)
    ret += values[i];
return ret / values.length;
doubleaverage(double[] values)
Returns the average (mean) of the given values.
double result = 0;
if (values == null) {
    throw new IllegalArgumentException("Cannot calculate average on a null object.");
if (values.length == 0) {
    return 0;
} else {
    for (Number n : values) {
...
doubleaverage(final double[] values)
average
double average = 0;
for (final double value : values) {
    average += value;
final int divisor = values.length == 0 ? 1 : values.length;
return average / divisor;
floataverage(final Float... values)
average
float total = 0.0F;
for (final Float val : values)
    total += val;
return total / values.length;
floataverage(final float[] values)
average
final double size = values.length;
double avg = 0;
for (final float v : values)
    avg += v / size;
return (float) avg;
intaverage(final int totalAmount, final int orderCount)
average
return orderCount == 0 ? 0 : Math.round((100.0f * totalAmount / orderCount) / 100);
Doubleaverage(final T p_num1, final T p_num2)
average
if (p_num1 == null) {
    return p_num2 == null ? null : p_num2.doubleValue();
if (p_num2 == null) {
    return p_num1.doubleValue();
return (p_num1.doubleValue() + p_num2.doubleValue()) / 2.0;