How to sort an ArrayList?

后端 未结 20 2528
有刺的猬
有刺的猬 2020-11-22 06:19

I have a List of doubles in java and I want to sort ArrayList in descending order.

Input ArrayList is as below:

List testList = new Arr         


        
20条回答
  •  被撕碎了的回忆
    2020-11-22 06:55

    Use util method of java.util.Collections class, i.e

    Collections.sort(list)
    

    In fact, if you want to sort custom object you can use

    Collections.sort(List list, Comparator c) 
    

    see collections api

提交回复
热议问题