I am trying to sort one character array char[] input
based on another character's array frequency of each character char[] freq
A extremely simple example would be:
input: bey
freq input: bbbyye
output: after sorted would be "bye"
I am iterating over my freq input and putting a key value pair like the following question: char c is key; an int is the value.
Now; how do I sort input based on the frequency? My attempts to implement Comparator have met with failure. My code is now identical to the following accepted answer.
What I "want" to do is bad java or pseudo-code is:
char[] input;
Arrays.sort(input, new Comparator<Character>() {
@Override
public int compare(Character o1, Character o2) {
return counts.get(o2) - counts.get(o1); //counts is a static
//global hashmap with the frequency values
}
});
I do not expect that to work and it does not the error is The method sort(char[]) in the type Arrays is not applicable for the arguments (char[], new Comparator(){})