m类运行测试
public class m {
public static void main(String[] args) {
ArrayList<A> list = new ArrayList<A>();
A a1= new A();
a1.i=10;
list.add(a1);
A a2= new A();
a2.i=9;
list.add(a2);
DateComparator d =new DateComparator();
System.out.println("最大值: " + Collections.max(list, d).i);
System.out.println("最小值: " + Collections.min(list, d).i);
}
}
--------------------------------------
public classA{
int i;
}
---------------------------------
设置比较依据
public class DateComparator implements Comparator<a> {
@Override
public int compare(a o1, a o2) {
return (o1.i < o2.i ? -1 : (o1.i == o2.i ? 0 : 1));
}
}