您的位置:首页 > 其它

List中的对象进行排序

2014-04-21 19:31 190 查看
//商家类Store 按距离进行排序
public class ComparatorStore implements Comparator<Store>
{

@Override
public int compare(Store lhs, Store rhs) {
return lhs.getDistance() - rhs.getDistance();
}

}
//////////....................
//调用排序
List<Store> stores = new ArrayList<Store>();
stores.add(new Store("name",152));//名字,距离
stores.add(new Store("name",155));//名字,距离
stores.add(new Store("name",154));//名字,距离
stores.add(new Store("name",172));//名字,距离
stores.add(new Store("name",1511));//名字,距离
Collections.sort(AppManager.result, new ComparatorStore());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: