阵列的最小单元 [英] Minimum element of an array

查看:84
本文介绍了阵列的最小单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,在Java中,一个双击[]富

I have, in Java, a double[] foo.

是否有此数组中拉出最小值的库函数?我知道我可以建立一个,但库函数是否可用,这不是一个好的做法。有没有在 java.util.Arrays中的

Is there a library function for pulling out the minimum value in this array? I know I can build one, but that's not a good practice if a library function is available. There's nothing in java.util.Arrays.

(在C ++中,我们有的std :: min_element 等,甚至在C ++ 11新功能来获得在同一时间的最小值和最大值了!)

(In C++ we have std::min_element etc. and even a new function in C++11 to get the minimum and maximum out at the same time!)

推荐答案

好吧,集合类有这样的方法。

Well, Collections class has such method.

您可以写

Double[] arr = {0.5,0.7};
System.out.println("min = " + Collections.min(Arrays.asList(arr)));

或者把它缩短:

System.out.println("min = " + Collections.min(Arrays.asList(-67,-89,64,34)));

这篇关于阵列的最小单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆