我有下课.在这里,Iris是另一个具有某些属性的类.
public class Helper {
Iris iris;
double distance;
public Helper(Iris iris, double distance) {
this.iris = iris;
this.distance = distance;
}
}
我想对这个数组列表(即List< Helper> helperList)进行排序,根据距离参数降序.我写了以下方法,但它不起作用.
public void sort(){
for(int k=0; k < helperList.size(); k++)
{
double distance = helperList.get(k).distance;
for(int l=0; l < helperList.size(); l++)
{
Helper temp = helperList.get(l);
if( distance < temp.distance )
{
helperList.set(l, helperList.get(k));
helperList.set(k, temp);
}
}
}
}
有人可以提出解决方案吗?