Java: How do I sort multiple ArrayList by their size?

后端 未结 2 894
北荒
北荒 2021-02-07 21:45

I have 9 different ArrayList and I want to have a list of the top 5.

I\'m thinking of sorting those ArrayLists by their sizes.

Is it

2条回答
  •  轮回少年
    2021-02-07 22:02

    you can do like this as well

    public static  List> sort(List> list) {
            list.sort((xs1, xs2) -> xs1.size() - xs2.size());
            return list;
        }
    

提交回复
热议问题