我已经实现了一个Comparator类,可以根据列表的大小对列表元素进行排序。代码如下:
public class SizeComparator implements Comparator< AppModel> {
@Override
public int compare( AppModel lhs, AppModel rhs ) {
double i1 = lhs.getCache();
double i2 = rhs.getCache();
if ( i1 > i2 )return +1;
else if (i1 < i2 )return -1;
return 0;
}
}
方法getCache()返回double。
sort函数的调用如下:
Collections.sort(installedApps, new SizeComparator());
但是应用程序仍未根据其大小进行排序。不知道我哪里出错了。有人可以帮助我吗?