Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

I am sorting the array list of dates in descending order by date using

Collections.sort(birthdayList);

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

i.e.

unsorted

bdaylist   namelist

1/20/1980 - Bob

3/15/1970 - Todd

8/25/1990 - Jeff

becomes

sorted

3/15/1970 - Todd

1/20/1980 - Bob

8/25/1990 - Jeff

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

Thank you very much!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
142 views
Welcome To Ask or Share your Answers For Others

1 Answer

  • Create a Person class with 2 fields: name and birthday.
  • Put the persons in a list
  • sort with a custom comparator that compares the birthdays

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...