Here is an simple example how easy sorting map is in Java 1.8
public class SortingMapExample {
public Map getSortedMap(){
Map<K,V> sortedMap = inputMap.entrySet().stream()
.sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
return sortedMap;
}
}
No comments:
Post a Comment