Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import static java.util.Map.Entry.comparingByKey;
- import static java.util.Map.Entry.comparingByValue;
- import static java.util.stream.Collectors.toMap;
- public class demo {
- public static void main(String[] args) {
- //Map with value list -> sorting by count of list elements
- Map<String, List<String>> map = new HashMap<>();
- map
- .entrySet()
- .stream()
- .sorted((a, b) -> b.getValue().size() - a.getValue().size())
- .forEach(pair -> {
- System.out.println(pair.getKey());
- pair.getValue().forEach(el -> System.out.println(el));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment