java中list按某个字段内容排序
/** * 按照部门名称排序 导出培训记录明细 * @param logsList * @return */ public List<ExcelUserTrainingDetailImporter> searchDetail(List<ExcelUserTrainingDetailImporter> logsList){ Collections.sort(logsList, new Comparator<ExcelUserTrainingDetailImporter>() { public int compare(ExcelUserTrainingDetailImporter o1, ExcelUserTrainingDetailImporter o2) { String dept1=o1.getParentDept(); dept1=Func.isEmpty(dept1)?"":dept1; String dept2=o2.getParentDept(); dept2=Func.isEmpty(dept2)?"":dept2; if (dept1.compareTo(dept2)<0){ return -1; } if (dept1.compareTo(dept2)==0){ return 0; } return 1; } }); return logsList; }