class test {
//状态
private int state;
//时间
private Date time;
public test(int state, Date time) {
this.state = state;
this.time = time;
}
public int getState() {
return state;
public void setState(int state) {
public Date getTime() {
return time;
public void setTime(Date time) {
@Override
public String toString() {
return "test{" +
"state=" + state +
", time=" + DateUtils.formatDateYMD(time) +
'}';
}
class testRun {
public static void main(String[] args) {
List<test> testList = new ArrayList<>();
Date d = DateUtils.now();
for (int i = 1; i <= 3; i++) {
test t = new test(i, DateUtils.addDays(d, i));
testList.add(t);
}
test t = new test(i, DateUtils.addMonths(d, i));
testList.forEach(o -> {
System.out.println(o.toString());
});
List<test> sort = testList.stream().sorted(Comparator.comparing(test::getState).thenComparing(test::getTime,Comparator.reverseOrder())).collect(toList());
System.out.println("------------------------------------");
sort.forEach(o -> {