1,创建实现接口Compartor 的类,泛型参数为集合数据类对象
public class CompanyCapitalFlowsMainASC implements Comparator<CompanyCapitalFlowsMainBean> {
@Override
public int compare(CompanyCapitalFlowsMainBean lhs, CompanyCapitalFlowsMainBean rhs) {
// TODO Auto-generated method stub
Long lhslong = lhs.getDt();
Long rhslong = rhs.getDt();
if (lhslong != null && rhslong != null) {
if (lhslong - rhslong > 0)
return 1;
if (lhslong - rhslong < 0)
return -1;
}
return 0;
}
}
以返回数值为-1 排序是升序还是降序
2,集合数据排序
List<CompanyCapitalFlowsMainBean> companyBusinessProfiles = new Arraylist<>();
CompanyCapitalFlowsMainASC companyCapitalFlowsMainASC = new CompanyCapitalFlowsMainASC();
Collections.sort(companyBusinessProfiles, companyCapitalFlowsMainASC);