I want to write a generic comparator class which will sort my ArrayList. In order to do so, what should I exactly write inside my compare function of static class ElementComparator?
public static void main(String[] args) throws InterruptedException {
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(-2);
list.add(-1);
list.add(10);
Collections.sort(list,new ElementComparator());
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
static class ElementComparator <T extends Comparable<T>> implements Comparator <T> {
@Override
public int compare(T o1, T o2) {
}
};