[英]Sort two ArrayLists, one relative to the other
I want to sort one ArrayList
used to display to the user: 我想对用于显示给用户的一个
ArrayList
进行排序:
String[] listOne = {whip, amulet, cape};
Then sort a second ArrayList
used as backed data relative to the first list being sort: 然后,相对于要排序的第一个列表,对用作支持数据的第二个
ArrayList
进行排序:
String[] listTwo = {abyssal_whip, amulet_of_power, strength_cape};
Is there any way I can do this? 有什么办法可以做到吗?
Don't store two related pieces of data in separate arrays. 不要将两个相关的数据存储在单独的数组中。
Instead create a custom Object that contains both pieces of data. 而是创建一个包含两个数据段的自定义对象。 Then you can implement
Comparable
on your class or write a custom Comparator
to do the sorting for you. 然后,您可以在您的类上实现
Comparable
或编写自定义Comparator
来为您进行排序。
For example check out: Sorting using Comparator- Descending order (User defined classes) 例如,检出: 使用比较器降序排序(用户定义的类)
for an example that shows you how to: 为示例向您展示如何:
Comparator
or implement Comparable
. Comparator
或实现Comparable
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.