Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

get top 3 entries based on values map java

//Get top 3 entries of a map, compared by value
Map<String,Integer> mapWithTop3Entries = hm.entrySet().stream().sorted(Map.Entry.<String, Integer>comparingByValue().reversed()).limit(3).collect(Collectors.toMap(Map.Entry::getKey,Map.Entry::getValue));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #top #entries #based #values #map #java
ADD COMMENT
Topic
Name
6+6 =