I'm new in Java and now I try lambda/stream.
How can I sort the Map
by value?
I tried as follows, but it's not correct:
time = time.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getValue))
.collect(Collectors.toMap((String)Map.Entry::getKey,
(Long)Map.Entry::getValue, LinkedHashMap::new));
I found the following method, but don't know how to use it:
Collector<T, ?, M> toMap(Function<? super T, ? extends K> keyMapper,
Function<? super T, ? extends U> valueMapper,
BinaryOperator<U> mergeFunction,
Supplier<M> mapSupplier)