I am trying to use the value of freq to sort all the a-z chars. However it is not working. Could someone explain why the following code is not working please? And how can I sort the array as I want? Thank you.
char[] chars = new char[26];
int[] freq = new int[26];
for(int i = 0;i<26;i++){
chars[i] = (char)(i+'a');
}
for(char c:s.toCharArray()){
freq[c-'a']++;
if(freq[c-'a']>(s.length()+1)/2){
return "";
}
}
Arrays.sort(chars, (a, b)->(freq[b-'a'] - freq[a-'a']));
error: no suitable method found for sort(char[],(a,b)->(fr[...]'a'])) Arrays.sort(chars, (a, b)->(freq[b-'a'] - freq[a-'a'])); ^ 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>)