람다식!
List<Map.Entry<String, Integer>> entryList = new LinkedList<>(scoreMap.entrySet());
entryList.sort(new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o2.getValue() - o1.getValue();
}
});
List<Map.Entry<String, Integer>> entryList = new LinkedList<>(scoreMap.entrySet());
entryList.sort(new Comparator<>() {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o2.getValue() - o1.getValue();
}
});
List<Map.Entry<String, Integer>> entryList = new LinkedList<>(scoreMap.entrySet());
entryList.sort((o1, o2) -> o2.getValue() - o1.getValue());
int minSize = Math.min(4,entryList.size()-1);
for (int i = 0; i <= minSize; i++) {
answer.add(entryList.get(i).getKey());
}