import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
List reList = new ArrayList();
Collections.sort(reList, new Comparator() {
// Parameters:
// o1 - the first object to be compared.
// o2 - the second object to be compared.
// Returns:
// a negative integer, zero, or a positive integer as the first
// argument is less than, equal to, or greater than the second.
// Throws:
// ClassCastException - if the arguments' types prevent them from
// being compared by this Comparator.
public int compare(Object o1, Object o2) {
// TODO Auto-generated method stub
return 0;
}
});
此博客展示了Java代码,通过import语句引入相关类,创建列表并使用Collections.sort方法对列表进行排序。定义了一个比较器,用于比较两个对象,根据比较结果返回负整数、零或正整数,还提及了可能抛出的异常。
1万+

被折叠的 条评论
为什么被折叠?



