Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MapsLambdaStreamAPI.Exercise;
- import java.util.*;
- public class O8CompanyUsers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String command = scanner.nextLine();
- Map<String, List<String>> companyUsers = new TreeMap<>();
- while (!command.equals("End")) {
- String[] tokens = command.split("\\s+->\\s+");
- String company = tokens[0];
- String users = tokens[1];
- if (!companyUsers.containsKey(company)) {
- companyUsers.put(company, new ArrayList<>());
- }
- if (!companyUsers.get(company).contains(users)) {
- companyUsers.get(company).add(users);
- }
- command = scanner.nextLine();
- }
- companyUsers.forEach((key, value) -> {
- System.out.println(key);
- value.forEach(users -> System.out.println("-- " + users));
- });
- //for (String s : companyUsers.keySet()) { // <- и този начин работи
- // System.out.printf("%s\n", s);
- // for (int i = 0; i < companyUsers.get(s).size(); i++) {
- // System.out.printf("-- %s\n", companyUsers.get(s).get(i));
- // }
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment