对象的数组列表 - 最小值 [英] Arraylist of objects - smallest value

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

问题描述

我有一个对象数组列表,并且这些对象具有双重"值.我需要打印出所有对象,并首先打印具有最高值的对象,最后打印具有最低值的对象.

I have an arraylist of objects, and the objects have "double" values. I need to print out all the objects, and have the object with the highest value printed first, and the object with the lowest value last.

我也尝试使用集合对数组列表进行排序然后打印,但我似乎无法让它工作.

I have also tried to use Collections to sort the arraylist and then print, but I can't seem to get it to work.

我的数组列表是:

ArrayList<Transition> transitions = new ArrayList<Transition>();

当我尝试使用 Collections 时:

When i tried to used Collections i used:

Object minValue = Collections.min(transitions);

希望你们中的一些人可以提供帮助:)

Hope some of you can help :)

推荐答案

如果 Transition 对象实现了 Comparable 接口试试这种方式.它应该可以工作.

If Transition object implemented Comparable interface try this way. It should work.

 Collections.sort(transitions);
 Transition transition = transitions.get(0);

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

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