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>> information = new LinkedHashMap<>();
- while (!"End".equals(input = scanner.nextLine())){
- String[] data = input.split("->");
- String companyName = data[0];
- String employeeId = data[1];
- if (!information.containsKey(companyName)){
- information.put(companyName,new ArrayList<>());
- information.get(companyName).add(employeeId);
- }else {
- if (!information.get(companyName).contains(employeeId)){
- information.get(companyName).add(employeeId);
- }
- }
- }
- information.entrySet()
- .stream()
- .sorted((a,b) -> a.getKey().compareTo(b.getKey()))
- .forEach(e -> {
- System.out.println(e.getKey().trim());
- for (int i = 0; i < e.getValue().size(); i++) {
- System.out.printf("-- %s\n",e.getValue().get(i).trim());
- }
- });
- }
- }
RAW Paste Data
Copied