I am trying to sort a character array with a custom sort order in Java using a lambda function as comparator -
order = "edcba"
char[] arr = {'a','b','c','d','e'}
I am trying this code :
Arrays.sort(arr, (a,b)->Integer.compare(order.indexOf(a), order.indexOf(b)));
However, this gives me the following error -
Line 4: error: no suitable method found for sort(char[],(a,b)->Int[...]f(b)))
Arrays.sort(arr, (a,b)->Integer.compare(order.indexOf(a), order.indexOf(b)));
^
method Arrays.<T#1>sort(T#1[],Comparator<? super T#1>) is not applicable
(inference variable T#1 has incompatible bounds
equality constraints: char
lower bounds: Object)
method Arrays.<T#2>sort(T#2[],int,int,Comparator<? super T#2>) is not applicable
(cannot infer type-variable(s) T#2
(actual and formal argument lists differ in length)) where T#1,T#2 are type-variables:
T#1 extends Object declared in method <T#1>sort(T#1[],Comparator<? super T#1>)
T#2 extends Object declared in method <T#2>sort(T#2[],int,int,Comparator<? super T#2>)
I have tried using similar code before for integer arrays to success. Can someone explain where I am going wrong here?