如何在Java中对一个数组列表进行排序并以相同顺序设置另一个列表 [英] How to sort one array list and set the another list with same order in java

查看:858
本文介绍了如何在Java中对一个数组列表进行排序并以相同顺序设置另一个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个带String的数组列表.我想对一个arraylist进行排序,并以相同的顺序在Java中设置其他两个列表的元素.我可以对一个列表进行排序,但是如何使用已排序的列表顺序设置其他两个列表的元素.

I have three array lists with String .I want to sort one arraylist and with same order want to set the element of other two list in java. i can sort one list but how to set element of other two list with sorted list order.

感谢和问候 拉胡尔

Thanks and regards Rahul

推荐答案

到目前为止,最好的方法是重新考虑设计并将所有三个相关数据放入为此目的而设计的类的实例中,然后对一个ArrayList进行排序.

By far the best way to do this would be to rethink the design and put all three pieces of related data into instances of class designed for this purpose, then just sort the one ArrayList.

其他任何方法都可能涉及设置一些Map来保存String之间的关系,然后在对第一个列表进行排序后(困难的混乱)手动移动列表,或者编写自己的排序算法从而将后两个列表与第一个一起移动(可能更容易,但更糟的是混乱).

Any other method would involve either setting up some Maps to hold the relationships between the Strings, and then manually moving the lists around after sorting the first one (a difficult mess) or writing your own sorting algorithm which moved the second two lists in tandem with the first (probably easier, but an even worse mess.)

这篇关于如何在Java中对一个数组列表进行排序并以相同顺序设置另一个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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