1. 程式人生 > >對列表進行排序

對列表進行排序

private void sortList() {
//sort
Comparator itemComparator = new Comparator() {
public int compare(PanYuanItemBean a, PanYuanItemBean b) {
/方法一/
//return a.getDistance().compareTo(b.getDistance());

            double x = Double.parseDouble(a.getDistance());
            double y = Double.parseDouble(b.getDistance());
            return (int) (x - y);
        }
    };
    //方法二對小數有小誤差
    Collections.sort(mlist, itemComparator);
    //
    LogUtils.E(mlist.size() + "sort後--");
}