根据List中的某一字段,对List集合进行排序

package com.syxp.jobassign.util;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.apache.log4j.Logger;

import com.syxp.jobassign.entity.job.SpeciallyJob;

/**
 * 把查询出的List进行排序
 * 
 * @author 常宝龙
 * 
 */
public class SortList {

	private static final Logger logger = Logger.getLogger(SortList.class);

	/**
	 * 根据工作完成情况字段进行排序
	 * 
	 * @param speciallyJob
	 */
	public void sortByExecuteState(List<SpeciallyJob> list) {
		try {
			Collections.sort(list, new Comparator<SpeciallyJob>() {
				@Override
				public int compare(SpeciallyJob o1, SpeciallyJob o2) {
					return o1.getExecuteState().toString()
							.compareTo(o2.getExecuteState().toString());
				}
			});
		} catch (Exception e) {
			logger.error("", e);
		}
	}

}

 

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