Am I missing something? It gives an error on sort method (doesn't identify the comparator method) but if I use Integer type array then this error goes away. Can't we do this comparison with primitive type of arrays?
public class Test {
public static void main(String[] args) {
int a[]={21,58,89,45,73,24};
Arrays.sort(a,new Comparator<Integer>(){
@Override
public int compare(Integer o1, Integer o2) {
if(o1%10>o2%10) return -1;
return 1;
}
});
Signature of method is: public static <T> void sort(T[] a, Comparator<? super T> c)
so the first argument is generic and you cannot put there primitive type that's why you get an error. For such sorting you have predefined sort method which can take primitive arrays