import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class Test { public static void main(String[] args) { Map longLongMap = new HashMap(); List> entryListWithError = longLongMap.entrySet().stream() .sorted(Comparator.comparing(Map.Entry::getValue).reversed()) .limit(10) .collect(Collectors.toList()); List> entryListWithoutError = longLongMap.entrySet().stream() .sorted(Comparator.comparing(Map.Entry::getValue)) .limit(10) .collect(Collectors.toList()); } }