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);
- TreeMap<String, List<String>> users = new TreeMap<>();
- String input = sc.nextLine();
- while (!input.toLowerCase().equals("end")) {
- String[] tokens = input.split(" -> ");
- String company = tokens[0];
- String id = tokens[1];
- users.putIfAbsent(company, new ArrayList<>());
- if (!users.get(company).contains(id)) {
- users.get(company).add(id);
- }
- input = sc.nextLine();
- }
- users.entrySet().stream()
- .forEach(e -> {
- System.out.println(e.getKey());
- e.getValue().forEach(a -> System.out.println("-- " + a));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement