I'm trying to sort a HashMap using a stream :
public class sortByValue implements Sorting{
@Override
public LinkedHashMap<String,Integer> sort(Map map) {
return map.entrySet().stream().
sorted(Map.Entry.comparingByValue()).
collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(oldValue, newValue) -> oldValue, LinkedHashMap::new));
}
}
But it gives me an error :
Non-static method cannot be referenced from a static context
it is on the functions
Map.Entry::getKey,Map.Entry::getValue
But I saw the same example on the website.Maybe someone understands what the mistake is?