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 scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- LinkedHashMap<String, List<String>> companyName = new LinkedHashMap<>();
- while (!input.equals("End")) {
- String data[] = input.split(" -> ");
- if (companyName.containsKey(data[0])) {
- List<String> employees = companyName.get(data[0]);
- if (!employees.contains(data[1])) {
- employees.add(data[1]);
- }
- } else {
- List<String> employees = new ArrayList<>();
- employees.add(data[1]);
- companyName.put(data[0], employees);
- }
- input = scanner.nextLine();
- }
- companyName.entrySet()
- .stream()
- .sorted(Map.Entry.comparingByKey())
- .forEach(company -> { System.out.println(company.getKey());
- company.getValue()
- .forEach(employee -> System.out.println("-- " + employee));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment