Advertisement
meteor4o

JF-Maps-Exercise-08.CompanyUsers

Jul 15th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1.  
  2. import java.util.*;
  3.  
  4. public class CompanyUsers {
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.  
  8.         TreeMap<String, List<String>> users = new TreeMap<>();
  9.  
  10.         String input = sc.nextLine();
  11.  
  12.         while (!input.toLowerCase().equals("end")) {
  13.             String[] tokens = input.split(" -> ");
  14.             String company = tokens[0];
  15.             String id = tokens[1];
  16.  
  17.             users.putIfAbsent(company, new ArrayList<>());
  18.  
  19.                 if (!users.get(company).contains(id)) {
  20.                     users.get(company).add(id);
  21.                 }
  22.  
  23.             input = sc.nextLine();
  24.         }
  25.  
  26.         users.entrySet().stream()
  27.                 .forEach(e -> {
  28.                     System.out.println(e.getKey());
  29.                     e.getValue().forEach(a -> System.out.println("-- " + a));
  30.                 });
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement