public class TestAmount {
public static void main(String[] args) {
List<Amount> list = new ArrayList<Amount>();
//创建3个对象,金额分别是7000、9000、8000,6000并将他们依次放入List中
Amount a1 = new Amount();
(7000d);
Amount a2 = new Amount();
(9000d);
Amount a3 = new Amount();
(8000d);
Amount a4 = new Amount();
(6000d);
(a1);
(a2);
(a3);
(a4);
(list, new Comparator<Amount>(){
/*
* int compare(Student o1, Student o2) 返回一个基本类型的整型,
* 返回负数表示:o1 小于o2,
* 返回0 表示:o1和o2相等,
* 返回正数表示:o1大于o2。
*/
public int compare(Amount o1, Amount o2) {
//按照金额大小进行降序排列
if(() < ()){
return 1;
}
if(() == ()){
return 0;
}
return -1;
}
});
// if (list != null && () > 0) {
//
//
for (Amount a : list) {
//
(());
//
}
// }
//降序获取前3个集合
if (list != null && () > 0) {
if (() > 3) {
list = (0, 3);
for (Amount a : list) {
(());
}
} else {
list = (0, ());
for (Amount a : list) {
(());
}
}
}
}
}
class Amount {
private String name;
private Double amount;
public String getName() {
return name;
}
public void setName(String name) {
= name;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
= amount;
}
}