Calculate the minimum and maximum values out of a list of doubles
import java.util.List;
publicclass 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
*/
publicstaticdouble[] minmax(List<Double> values) {
if (values.size() == 0) {
returnnewdouble[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);
}
returnnewdouble[] { min, max };
}
}