import java.util.*;
public class ABC {
public static void main(String[] args) {
List<Integer> values = null;
values = new ArrayList<Integer>();
values.add(5);
values.add(9);
values.add(3);
values.add(55);
values.add(4);
Collections.sort(values);
System.out.println(values);
values = new ArrayList<Integer>();
values.add(5);
values.add(9);
values.add(3);
values.add(55);
values.add(4);
Comparator<Integer> cmp = new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
int o1i = o1;
int o2i = o2;
return o1i - o1i;
}
};
Collections.sort(values, cmp);
System.out.println(values);
}
}
This prints:
[3, 4, 5, 9, 55]
[5, 9, 3, 55, 4]
which is obviously not the expected result. What am I missing?
You have a bug:
Change
to