import java.util.*;
public class C_2 {
public static void main(String args[]) {
String theStrings[] = { "x", "a", "b", "c", "d" };
List l = Arrays.asList(theStrings);
Collections.sort(l); // line a
Collections.sort(l, new ThisIsMyThing()); // line b
System.out.println(l);
}
}
class ThisIsMyThing implements Comparator {
public int compare(Object o1, Object o2) {
String s1 = (String)o1;
String s2 = (String)o2;
return -1 * s1.compareTo(s2);
}
}
我了解该课程C_2
基于两种不同的技术进行排序。一个是标准Collections.sort(l);
,另一个是Collections.sort(l,Comparator<>());
我无法理解这种排序方法。有人可以向我解释一下吗?