I have a problem with sorting the letters of a word, by the number of occurrences of the letters and if the letters appear the same number of times, it will be sorted at least lexicographically. I have a code but I get compilation error on the site and 0 points because they use java 7 and I don't know how to solve the last part of the problem without "lambda".
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class prog {
public static void main(String[] args) throws IOException {
String testString = " ";
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
testString = rd.readLine();
Map < Character, List < Character >> map = new HashMap < > ();
for (int i = 0; i < testString.length(); i++) {
char someChar = testString.charAt(i);
if (someChar == ' ') {
continue;
}
char ch = testString.charAt(i);
List < Character > characters =
map.getOrDefault(Character.toLowerCase(ch), new ArrayList < > ());
characters.add(ch);
map.put(Character.toLowerCase(ch), characters);
}
List < Map.Entry < Character, List < Character >>> list =
new ArrayList < > (map.entrySet());
list.sort((o1, o2) - > {
if (o1.getValue().size() == o2.getValue().size()) {
return o1.getKey() - o2.getKey();
}
return o2.getValue().size() - o1.getValue().size();
});
list.forEach(entry - > entry.getValue().forEach(System.out::print));
}
}