Sorting an ArrayList of objects using a custom sorting order

后端 未结 11 1520
说谎
说谎 2020-11-22 00:14

I am looking to implement a sort feature for my address book application.

I want to sort an ArrayList contactArray. Contact

11条回答
  •  梦毁少年i
    2020-11-22 00:33

    BalusC and bguiz have already given very complete answers on how to use Java's built-in Comparators.

    I just want to add that google-collections has an Ordering class which is more "powerful" than the standard Comparators. It might be worth checking out. You can do cool things such as compounding Orderings, reversing them, ordering depending on a function's result for your objects...

    Here is a blog post that mentions some of its benefits.

提交回复
热议问题