list排序

 

实现comparator接口即可。

 

package utils;

import java.util.Comparator;

import com.chebaobao.api.shop.nearshop.entity.Shop;

public class CompareShopDistance implements Comparator {
	@Override
	public int compare(Object o1, Object o2) {
		Shop shop1 = (Shop) o1;
		Shop shop2 = (Shop) o2;
		// 首先比较年龄,如果年龄相同,则比较名字
		return shop1.getDistancefromme().compareTo(shop2.getDistancefromme());
	}

}

 

 

 

refurl:http://www.blogjava.net/zygcs/archive/2008/01/17/176032.html

 

 

 

 

你可能感兴趣的:(list排序)