Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = "";
- Map<String, List<String>> data = new LinkedHashMap<>();
- System.out.println();
- while (!"end".equals(input = scanner.nextLine())){
- String[] list = input.split(":");
- String courseName = list[0];
- String studentName = list[1];
- data.putIfAbsent(courseName,new ArrayList<>());
- data.get(courseName).add(studentName);
- }
- data.entrySet()
- .stream()
- .sorted((a,b) -> Integer.compare(
- b.getValue().size(),
- a.getValue().size()))
- .forEach(e -> {
- System.out.printf("%s: %d\n",e.getKey().trim(),e.getValue().size());
- e.getValue()
- .stream()
- .sorted((a1,a2) -> a1.compareTo(a2))
- .forEach(u -> System.out.printf("-- %s\n",u.trim()));
- });
- }
- }
Add Comment
Please, Sign In to add comment