package com.xzz.jihepaixu; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import lombok.ToString; import java.util.Date; import java.io.Serializable; @Data @ToString public class JiHe implements Serializable, Comparable{ @JsonIgnore private Date endTime; @Override public int compareTo(JiHe o) { return endTime.compareTo(o.getEndTime()); } }
package com.xzz.jihepaixu; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import lombok.ToString; import java.io.Serializable; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; public class JiHeTest{ public static void main(String[] args) throws ParseException { ListarrayList = new ArrayList<>(); JiHe jiHe = new JiHe(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); Date parse = simpleDateFormat.parse("20210930000000"); jiHe.setEndTime(parse); JiHe jiHe1 = new JiHe(); SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyyMMddHHmmss"); Date parse1 = simpleDateFormat2.parse("20211231235959"); jiHe1.setEndTime(parse1); arrayList.add(jiHe); arrayList.add(jiHe1); //默认排序 从大往小排序 Collections.sort(arrayList); System.out.println(arrayList); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)