排序2个数组列表的最佳方法? [英] Best way to sort 2 array lists?

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

问题描述

我有2个数组列表.一个是包含生日的数组列表.另一个是名称的数组列表.

I have 2 array lists. One is an array list containing birthdays. The other is an array list of names.

我正在使用

Collections.sort(birthdayList);

我想让名字的数组列表按照与生日列表相同的顺序进行排序.

I want to have the array list of names be sorted in the same order that the birthday list was.

未排序

bdaylist   namelist

1/20/1980 - Bob

3/15/1970 - Todd

8/25/1990 - Jeff

成为

已排序

3/15/1970 - Todd

1/20/1980 - Bob

8/25/1990 - Jeff

在Java中最有效的方法是什么?

What would be the most efficient way to do this in Java?

非常感谢!

推荐答案

  • 创建一个具有2个字段的Person类:姓名和生日.
  • 将人员放入列表
  • 使用自定义比较器对生日进行比较
  • 这篇关于排序2个数组列表的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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