How to sort a List<Object> alphabetically using Object name field

后端 未结 16 1452
暗喜
暗喜 2020-11-28 06:00

I have a List of Objects like List p.I want to sort this list alphabetically using Object name field. Object contains 10 field and name field is o
16条回答
  •  死守一世寂寞
    2020-11-28 06:19

    You can use sortThisBy() from Eclipse Collections:

    MutableList list = Lists.mutable.empty();
    list.sortThisBy(Campaign::getName);
    

    If you can't change the type of list from List:

    List list = new ArrayList<>();
    ListAdapter.adapt(list).sortThisBy(Campaign::getName);
    

    Note: I am a contributor to Eclipse Collections.

提交回复
热议问题