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;
	}

  

posted @ 2021-06-08 15:00  红尘沙漏  阅读(1069)  评论(0编辑  收藏  举报