I know how to create a priority Queue with the comparator class. Here I created a comparator class to compare 2 characters. My question is that how should I create a char array with the comparing methods? I tried the following: char[] helper = new char[](new StringNumComparator());.
public String Practice(String input) {
class StringNumComparator implements Comparator<Character> {
@Override
public int compare(Character a, Character b) {
if (Character.isAlphabetic(a) && Character.isAlphabetic(b)) {
return (int) a <= (int) b ? -1 : 1;
} else if (Character.isDigit(a) && Character.isDigit(b)) {
return Character.getNumericValue(a) <= Character.getNumericValue(b) ? -1 : 1;
}
return Character.isAlphabetic(a) ? -1 : 1;
}
}
char[] helper = new char[](new StringNumComparator());
return new String(helper);
}