对存放时间的ArrayList进行排序

xiaoxiao2021-02-28  34

import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; /** * @ClassName:DateListSort * @Description:对List中的日期进行排序 * @author:yaoshuai * @data:2018/4/24 */ public class DateSort { public static ArrayList DateListSort(ArrayList dateList) throws Exception{ ComparatorDate c = new ComparatorDate(); Collections.sort(dateList, c); return dateList; } } class ComparatorDate implements Comparator { public int compare(Object obj1, Object obj2) { Date begin = (Date) obj1; Date end = (Date) obj2; if (begin.after(end)) { return 1; } else { return -1; } } }
转载请注明原文地址: https://www.6miu.com/read-2049977.html

最新回复(0)