如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033
Reference:http://stackoverflow.com/questions/8093163/min-max-values-of-a-listdouble
现在有一个如下的数组,求其最大值和最小值
List<double[]> values = new ArrayList<double[]>(); values.add(new double[] { 12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 26.4, 26.1, 23.6, 20.3, 17.2, 13.9 }); values.add(new double[] { 10, 10, 12, 15, 20, 24, 26, 26, 23, 18, 14, 11 }); values.add(new double[] { 5, 5.3, 8, 12, 17, 22, 24.2, 24, 19, 15, 9, 6 }); values.add(new double[] { 9, 10, 11, 15, 19, 23, 26, 25, 22, 18, 13, 10 });
求其最大值:
public double ListDoubleArrayMax(List<double[]> dataList) { double max = Double.MIN_VALUE; for (double[] ds : dataList) { for (double d : ds) { if (d > max) { max = d; } } } return max; }
求其最小值:
public double ListDoubleArrayMin(List<double[]> dataList) { double min = Double.MAX_VALUE; for (double[] ds : dataList) { for (double d : ds) { if (d < min) { min = d; } } } return min; }
如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033
原文地址:http://blog.csdn.net/itas109/article/details/43635609