How correctly to implement the Comparator for the Treemap? It should: 1. Sort words by the length of the line in descending order. 2. Words of equal length sort alphabetically.
class Test implements Comparator<String> {
public static SortedMap<String, String> doSort(String str) {
Comparator<String> comparator = new Test();
SortedMap<String, String> map = new TreeMap<>(comparator);
//do something to input String
return map;
}
@Override
public int compare(String o1, String o2)
{
return o2.length() - o1.length();
}
}
is that enough? How to add alphabet sorting in the second turn?