How to sort a list of objects with some specific property

前端 未结 4 1533
-上瘾入骨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:50

    Read the JavaDoc for the Comparable interface. http://download.oracle.com/javase/6/docs/api/java/lang/Comparable.html. Or did you mean "don't want to implement Comparable" instead of "Comparator"?

    Comparable is quite standard actually, which is good for the maintenance of your code. The sort method in Collections is based on it, so it works pretty well.

提交回复
热议问题