Requirements: Java Map sorted by value (sorted by value, this example is flashback)
Method: Use java1.8 Stream to implement
It is best to use LinkedHashMap to return the accepted parameters to ensure that the order after the arrangement will not be disrupted.
public static <K extends Comparable, V extends Comparable> Map<K, V> sortMapByValues(Map<K, V> aMap) {
HashMap<K, V> finalOut = new LinkedHashMap<>();
()
.stream()
.sorted((p1, p2) -> ().compareTo(()))
.collect(()).forEach(ele -> ((), ()));
return finalOut;
}