-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourses.java
More file actions
32 lines (22 loc) · 903 Bytes
/
Copy pathCourses.java
File metadata and controls
32 lines (22 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package mapsLabdaStreamAPI;
import java.util.*;
public class Courses {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String inputLine = scanner.nextLine();
Map<String, List<String>> studentsMap = new LinkedHashMap<>();
while(!inputLine.equals("end")){
String course = inputLine.split(" : ")[0];
String nameStudent = inputLine.split(" : ")[1];
if(!studentsMap.containsKey(course)){
studentsMap.put(course,new ArrayList<>());
}
studentsMap.get(course).add(nameStudent);
inputLine = scanner.nextLine();
}
studentsMap.entrySet().forEach(e ->{
System.out.printf("%s: %d%n",e.getKey(),e.getValue().size());
e.getValue().forEach(student -> System.out.printf("-- %s%n",student));
});
}
}