How to sort a list of objects with some specific property

前端 未结 4 1535
-上瘾入骨i
-上瘾入骨i 2021-01-20 13:38

I have a record object

 public Record{
   double simiADD;
 }

I Have a List of Record objects and I want to Sort on simiADD. Record with le

4条回答
  •  抹茶落季
    2021-01-20 13:42

    If you don't want to define a comparison function inside the Record class:

    Collections.sort(recordList, new Comparator() {
            public int compare(Record object1, Record object2) {
                return Double.compare(object1.simiADD, object2.simiADD);
            }
        }
    );
    

提交回复
热议问题