Reordering a collection according to a related list of ids

后端 未结 6 1574
一向
一向 2021-01-16 06:52

I have a Collection (unordered) of objects with an id property, and an (ordered) List of ids. The id list is not sorted. I\'d like to crea

6条回答
  •  难免孤独
    2021-01-16 07:10

    You can:

    • implement the interface Comparable in your object and then call Collections.sort(List)
    • implement the interface Comparator with a new class and then call Collections.sort(List, Comparator)

    With the first solution you have to modify your object, with the second one you have to create another class but you can leave your object unmodified. is your object class.

提交回复
热议问题