如何找到ArrayList的最小值? [英] How do you find the smallest value of an ArrayList?

查看:149
本文介绍了如何找到ArrayList的最小值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个称为子级的数组列表,其对象在GUI中的某些整个值距离内移动,我需要找到这些值中的最小值并将其打印到控制台.

I have an array list called children that has objects that move around certain whole value distances in the GUI and I need to find the smallest of these values and print it to the console.

我很确定这需要for循环吗?我只是不知道如何正确地构造它,以确保它查看子项" ArrayList 中的值.还是Eclipse中有一些内置功能可以计算数组列表的最小值?

I'm pretty sure this calls for a for loop right? I just don't know how to structure it correctly to make sure it looks at the values within the "children" ArrayList. Or is there some built in functionality within Eclipse to calculate the smallest value of an array list?

推荐答案

Collection类具有静态方法,用于查找Collection中最小或最大的元素.例如:

The Collection class has static methods for finding the smallest or the largest element in a Collection. For example:

 System.out.println("max: " + Collections.max(list));
 System.out.println("min: " + Collections.min(list));

这篇关于如何找到ArrayList的最小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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