I would like to order a HashMap
:
Map<Integer, Set<Integer>> unsorted
by the size of the value set. I attempted to do it as follows:
Map<Integer, Set<Integer>> sorted = unsorted.entrySet().stream()
.sorted(comparingInt(e->e.getValue().size()))
.collect(toMap(
Map.Entry::getKey,
Map.Entry::getValue,
LinkedHashMap::new
));
but got an error
"Non-static method cannot be referenced from a static context"
. I am new to Java 8 Streams and am clearly missing something trivial - what is it?