I have this HashMap Map<Person, List<Information>>
. How can I sort this map in reversed order by the double attribute in class Person
?
I tried this:
origin.entrySet().stream()
.sorted(Comparator.comparingDouble(k -> k.getKey().getScore())
.collect(
Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(oldValue, newValue) -> oldValue,
LinkedHashMap::new));
It works, but since I use the function .reversed
at the end of getScore()
then getKey()
returns error. Cannot resolve method 'getKey' in 'Object
Class Person:
public class Person{
double score;
Information information;
}