Sort map by value using lambdas and streams

You can always start reading the documentation and some tutorials.

map.entrySet().stream()
        .sorted(Map.Entry.<String, Integer>comparingByValue().reversed()) 
        .limit(10) 
        .forEach(System.out::println); // or any other terminal method

Reference

http://www.leveluplunch.com/java/examples/sort-order-map-by-values/

Leave a Comment