Sorting an ArrayList of objects using a custom sorting order

后端 未结 11 1656
说谎
说谎 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条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 00:50

    By using lambdaj you can sort a collection of your contacts (for example by their name) as it follows

    sort(contacts, on(Contact.class).getName());
    

    or by their address:

    sort(contacts, on(Contacts.class).getAddress());
    

    and so on. More in general, it offers a DSL to access and manipulate your collections in many ways, like filtering or grouping your contacts based on some conditions, aggregate some of their property values, etc.

提交回复
热议问题