Util.java Source code

Java tutorial

Introduction

Here is the source code for Util.java

Source

import java.util.List;

public class Util {
    /**
     * Calculate the minimum and maximum values out of a list of doubles.
     * 
     * @param values
     *            the input values
     * @return an array with the minimum and maximum values
     */
    public static double[] minmax(List<Double> values) {
        if (values.size() == 0) {
            return new double[2];
        }
        double min = values.get(0);
        double max = min;
        int length = values.size();
        for (int i = 1; i < length; i++) {
            double value = values.get(i);
            min = Math.min(min, value);
            max = Math.max(max, value);
        }
        return new double[] { min, max };
    }

}