写道
@SuppressWarnings("unchecked")
public void testConlletctionsSort() throws Exception {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(1);
list.add(7);
list.add(2);
list.add(3);
list.add(2);
list.add(4);
list.add(3);
list.add(10);
Collections.sort(list, new Comparator() {
public int compare(Object o1, Object o2) {
Integer first = (Integer) o1;
Integer second = (Integer) o2;
int i = first.compareTo(second);
System.out.print(first);
System.out.print("-");
System.out.print(second);
System.out.print(" ");
System.out.print(i);
System.out.print(",");
return i;
}
});
System.out.println("\n");
for (Integer amount : list) {
System.out.print(amount);
System.out.print(",");
}
}
public void testConlletctionsSort() throws Exception {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(1);
list.add(7);
list.add(2);
list.add(3);
list.add(2);
list.add(4);
list.add(3);
list.add(10);
Collections.sort(list, new Comparator() {
public int compare(Object o1, Object o2) {
Integer first = (Integer) o1;
Integer second = (Integer) o2;
int i = first.compareTo(second);
System.out.print(first);
System.out.print("-");
System.out.print(second);
System.out.print(" ");
System.out.print(i);
System.out.print(",");
return i;
}
});
System.out.println("\n");
for (Integer amount : list) {
System.out.print(amount);
System.out.print(",");
}
}
结果:
1-1 0,1-7 -1,7-2 1,1-2 -1,3-2 1,3-4 -1,4-3 1,3-3 0,4-10 -1,7-2 1,1-2 -1,1-2 -1,2-2 0,7-2 1,7-3 1,7-3 1,7-4 1,7-10 -1,
1,1,2,2,3,3,4,7,10,
Process finished with exit code 0