package com.study.other;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CompareQuestion {
private static class Demo implements Comparable<Demo> {
private BigDecimal prop1;
public BigDecimal getProp1() {
return prop1;
}
public void setProp1(BigDecimal prop1) {
this.prop1 = prop1;
}
@Override
public int compareTo(Demo o) {
return o.prop1.compareTo(this.prop1) == 0 ? -1 : o.prop1.compareTo(this.prop1);
}
}
public static void main(String[] args) {
int[] array = new int[]{1, 2, 3, 1, 2, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1};
int len = array.length;
System.out.println(len);
List<Demo> list = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
Demo obj = new Demo();
obj.setProp1(new BigDecimal(array[i]));
list.add(obj);
}
Collections.sort(list);
}
}
网友评论