如何排序的java对象的ArrayList? [英] How to sort an arraylist of objects java?

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

问题描述

所以,我想在Java对象的ArrayList

So I want an arraylist of objects in java.

object1.number object2.number object3.number ,等...但这些对象另外还有其他属性数量,如名称距离,等...

I have object1.number and object2.number, object3.number, etc... but those objects have other properties besides number, such as name, distance, etc...

因此​​,如果正在整理在一个字符串数组这纯粹是,把一个字符串中时间而让另一个字符串取代其位置......但在 araryList 的对象,我该怎么办呢?

So if it was sorting a string in a array it would just be, put a string in a temporal and let the other string take its place... but in an araryList of objects, how can I do it?

我可以只移动对象的数组中的位置?

Can I just move objects to that position of the array?

感谢。

推荐答案

实现您自己的比较器:

Arrays.sort(yourArray, new Comparator<YourClass>() {
        @Override
        public int compare(YourClass o1, YourClass o2) {
            //compare object properties
        }
});

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

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