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

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

问题描述

我有一个名为 children 的数组列表,其中包含在 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天全站免登陆