Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class CompanyUsers {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String command = sc.nextLine();
- LinkedHashMap<String, ArrayList<String>> hashMap = new LinkedHashMap<>();
- while (!command.equalsIgnoreCase("End")) {
- String[] input = command.split(" -> ");
- String name = input[0];
- String id = input[1];
- hashMap.putIfAbsent(name, new ArrayList<>());
- if(!hashMap.get(name).contains(id)){
- hashMap.get(name).add(id);
- }
- command = sc.nextLine();
- }
- hashMap.entrySet()
- .stream()
- .sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey()))
- .forEach(e -> {
- System.out.printf("%s%n", e.getKey());
- for (int i = 0; i < e.getValue().size(); i++) {
- System.out.printf("-- %s%n", e.getValue().get(i));
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement